Print The Following Pattern For Given Number Of Rows by using Java Program
Pattern:
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
1 1 1 1 1
Code:
import java.util.*;
public class Pattern
{
public static void main(String[] args)
{
int i,j,k,n;
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter The Number Of Rows : ");
n = sc.nextInt();
System.out.println();
for(i=1;i<=n;i++)
{
int c=1,d=0;
for(j=1;j<=i;j++)
{
System.out.print(c+" ");
}
for(k=n;k>i;k--)
{
System.out.print(d+" ");
}
System.out.println();
}
System.out.println();
}
}
Output of program:
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
1 1 1 1 1
Code:
import java.util.*;
public class Pattern
{
public static void main(String[] args)
{
int i,j,k,n;
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter The Number Of Rows : ");
n = sc.nextInt();
System.out.println();
for(i=1;i<=n;i++)
{
int c=1,d=0;
for(j=1;j<=i;j++)
{
System.out.print(c+" ");
}
for(k=n;k>i;k--)
{
System.out.print(d+" ");
}
System.out.println();
}
System.out.println();
}
}
Output of program:
No comments