Explanation :
If n=5 then output will be
1
10
101
1010
10101.
Code:
import java.util.Scanner;public class Pattern25
{
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,k;
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
System.out.printf("%d",j%2);
}
System.out.printf("\n");
}
sc.close();
}
}
No comments:
Post a Comment