Following code will print the following pattern:
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
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=1;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
a[j][i]=k++;
}
}
System.out.println("Pattern is :");
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.Piyush Arora for This Program....
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
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=1;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
a[j][i]=k++;
}
}
System.out.println("Pattern is :");
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.Piyush Arora for This Program....