Following code will print the following pattern:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
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();
System.out.println("Enter Number of Columns");
int m=in.nextInt();
int k=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
a[i][j]=k++;
}
}
System.out.println("Pattern is :");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
Output:
Special Thanks To Mr.Navneet Singh For This Program....
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
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();
System.out.println("Enter Number of Columns");
int m=in.nextInt();
int k=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
a[i][j]=k++;
}
}
System.out.println("Pattern is :");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
Output:
Special Thanks To Mr.Navneet Singh For This Program....