Java

Program to Print a Pattern in Java

By June 3, 2016 November 9th, 2016 No Comments

/**** Program to Print a Pattern
1
11
101
1001
10001 ****/

class floyd2
{
public static void main(String ar[])
{
int i, j, k = 1;
System.out.println(“Floyd’s triangle”);
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
if ( j == 1 || j == I )
k = 1;
else
k = 0;
System.out.print(k+” “);
}
System.out.print(“\n”);
}
}
}

Output:





Screenshot (282)

Leave a Reply