If n=5 then output will be
11111
0000
111
00
1 .
Code:
import java.util.Scanner;public class Pattern26
{
public static void main( String args[])
{
System.out.print("Enter the number of rows:");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i, j;
for (i=n;i>=1;i--)
{
for (j=1;j<=i;j++)
{
System.out.printf("%d",i%2);
}
System.out.printf("\n");
}
sc.close();
}
}
No comments:
Post a Comment