//This java program accepts a number of user
//which tells the program that how many lines
//of the pattern will be printed.
/*Sample Input :6
Sample Output :
0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
5 4 3 2 1 0 1 2 3 4 5 */
import java.util.*;
class pattern
{
public static void main()
{
System.out.println("Enter a number");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i,j;
for(i=0;i<=n;i++)
{
for(j=0;j<=(2*(n-i));j++)
{
System.out.print(" ");
}
for(j=i;j>=0;j--)
{
System.out.print(j+" ");
}
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
//Author : Mayank Rajoria
//which tells the program that how many lines
//of the pattern will be printed.
/*Sample Input :6
Sample Output :
0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
5 4 3 2 1 0 1 2 3 4 5 */
import java.util.*;
class pattern
{
public static void main()
{
System.out.println("Enter a number");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i,j;
for(i=0;i<=n;i++)
{
for(j=0;j<=(2*(n-i));j++)
{
System.out.print(" ");
}
for(j=i;j>=0;j--)
{
System.out.print(j+" ");
}
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
//Author : Mayank Rajoria
No comments:
Post a Comment