To print the following series given the number of rows.

Chikul
Posted by Chikul under Others category on | Views : 1687
For e.g. Input = 5, the output must be displayed as follows:
1
1 0
1 0 1
1 0 0 1
1 0 0 0 1


import java.io.*;
import java.lang.*;

public class Print_Format
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String : ");
int i=Integer.parseInt(br.readLine());

if(i==1)
{
System.out.println("1");
}
if(i==2)
{
System.out.println("1");

System.out.print("0");
}
if(i>2)
{
System.out.println("1");
System.out.println("");
System.out.println("1 0");
int p=i+1;
for(int k=3;k<p;k++)
{
int t=2;
System.out.println("");
System.out.print("1 ");
while(t<k)
{
System.out.print("0 ");
t++;
}
System.out.print("1");
System.out.println("");
}

}
}}

Comments or Responses

Login to post response