Number Pattern 3
Send Feedback
Print the following pattern for the given N number of rows.
Pattern for N = 4
Input format :
Output format :
Sample Input :
Sample Output :
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