In the program the following pattern will be printed.
1
212
32123
4321234
543212345
The program is shown below :
import java.util.*;
class pattern10
{
public static void main(String args[])
{
Scanner scr=new Scanner(System.in);
System.out.println("Enter the number of rows ");
int n=scr.nextInt();
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n-i;++j)
{
System.out.print(" ");
}
for(int k=i;k>=1;--k)
{
System.out.print(k);
}
for(int l=2;l<=i;++l)
{
System.out.print(l);
}
System.out.println();
}
}// end of main method
}// end of main class
OUTPUT
C:\Users\Ravi\Desktop\ravi>javac pattern10.java
C:\Users\Ravi\Desktop\ravi>java pattern10
Enter the number of rows
6
1
212
32123
4321234
543212345
65432123456
No comments:
Post a Comment