package demo;
import java.util.Scanner;
public class NumberPattern
{
public static void main(String[] args)
{
int num, n;
Scanner sc = new Scanner(System.in);
System.out.print("Enter any number : ");
num = sc.nextInt();
n = num;
for (int r = 1; r <= num; r++, n--)
{
for (int c = 1; c <= n; c++)
{
System.out.print(c);
}
for (int c = n - 1; c >= 1; c--)
{
System.out.print(c);
}
System.out.println();
}
}
}
Output:
Enter any number : 5
123454321
1234321
12321
121
1
BUILD SUCCESSFUL (total time: 3 seconds)
|
No comments:
Post a Comment