Explanation :
If n=6 then output will be
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36.
Code:
import java.util.Scanner;public class Pattern27
{
public static void main( String args[])
{
System.out.print("Enter the number of rows:");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i,j;
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
System.out.printf("%d ",i*j);
}
System.out.printf("\n");
}
sc.close();
}
}
No comments:
Post a Comment