Sunday, March 11, 2018

Number Pattern 3

Number Pattern 3
Send Feedback

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

Pattern for N = 4
1
11
121
1221
Input format :
Integer N (Total no. of rows)
Output format :
Pattern in N lines
Sample Input :
5
Sample Output :
1
11
121
1221
12221

import java.util.Scanner;

public class Main
{

public static void main(String[] args)

{
Scanner s = new Scanner(System.in);
int row = s.nextInt();

if(row>=1)
{
for(int i =0; i<row;i++)
{
for(int j=0;j<=i;j++)
{
if(i==0)
{
System.out.print("1");

}
else if(j==0 || j==i)
{
System.out.print(1);
}
else
{
System.out.print("2");

}

}
System.out.println();

}


}

}

}

No comments:

Post a Comment