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