Following code will print a pattern like given below:
0
1 2
3 4 5
6 7 8 9
Code::
import java.util.*;
public class Pattern
{
public static void main(String[] nt)
{
int a[][]=new int[20][20];
System.out.println("Enter The Number of Rows");
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int k=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
a[i][j]=k++;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
Output:
Special Thanks to Mr. Garvit Abbat for this Program.....
0
1 2
3 4 5
6 7 8 9
Code::
import java.util.*;
public class Pattern
{
public static void main(String[] nt)
{
int a[][]=new int[20][20];
System.out.println("Enter The Number of Rows");
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int k=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
a[i][j]=k++;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
Output:
Special Thanks to Mr. Garvit Abbat for this Program.....