Explanation :
If n=6 then output will be
123456
23456
3456
456
56
6.
Code:
import java.util.Scanner;public class Pattern7
{
public static void main( String args[])
{
System.out.print("Enter the number of rows:");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i = 1 ; i <= n ; i++)
{
for(int k = n - i ; k < n - 1 ; k++)
{
System.out.print(" ");
}
for(int j = i ; j <= n ; j++)
{
System.out.print(j);
}
System.out.println();
}
sc.close();
}
}
No comments:
Post a Comment