Sunday, March 11, 2018

Number Pattern 4

Number Pattern 4
Send Feedback

Print the following pattern for the given N number of rows.

Pattern for N = 4
1234
123
12
1
Input format :
Integer N (Total no. of rows)
Output format :
Pattern in N lines
Sample Input :
5
Sample Output :
12345
1234
123
12
1

import java.util.Scanner;
public class Main
{

public static void main(String[] args)
{
    Scanner s = new Scanner(System.in);
int n = s.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();
}
}
}

No comments:

Post a Comment