Explanation :
If n=6 then output will be
123456
12345
1234
123
12
1.
Code:
import java.util.Scanner;public class Pattern6
{
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, r = n; i <= n ; i++ ,r--)
{
for(int j = 1 ; j <= r ; j++)
{
System.out.print(j);
}
System.out.println();
}
sc.close();
}
}
No comments:
Post a Comment