import java.util.Scanner;
public class Pattern27
{
public static void main(String[] args)
{
// create scanner class object.
Scanner sc = new Scanner(System.in);
// input row for printing pattern.
System.out.print("Enter row for pattern : ");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
// loop for printing pattern.
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
sc.close();
}
}
import java.util.Scanner;
public class Pattern28
{
public static void main(String[] args)
{
// create scanner class object.
Scanner sc = new Scanner(System.in);
// input row for printing pattern.
System.out.print("Enter row for pattern : ");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
// this loop will print the pattern in two parts first half and second half.
for (int i = rows; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
for (int i = 2; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
sc.close();
}
}
Output
Enter row for pattern : 5
Here is your pattern....!!!
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program to print pattern 1 in java
Output
Program to print pattern 2 in java
Output
need an explanation for this answer? contact us directly to get an explanation for this answer