import java.util.Scanner;
public class Number
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("How many rows you want in this pattern?");
int rows = scan.nextInt();
System.out.println(" Numeber pattern");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
for (int i = rows-1; i >= 1; i--)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
scan.close();
}
}
OUTPUT:
How many rows you want in this pattern?
5
Numeber pattern
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
public class Number
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("How many rows you want in this pattern?");
int rows = scan.nextInt();
System.out.println(" Numeber pattern");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
for (int i = rows-1; i >= 1; i--)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
scan.close();
}
}
OUTPUT:
How many rows you want in this pattern?
5
Numeber pattern
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
No comments:
Post a Comment