Printing the following pattern using BlueJ.
1
1 2 2 1
1 2 4 4 2 1
1 2 4 8 8 4 2 1
1 2 4 8 16 16 8 4 2 1
1 2 4 8 16 32 32 16 8 4 2 1
1 2 4 8 16 32 64 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
import java.io.*;
class NumberPattern
{
String str;
int i,j,n,x=1,y=1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
void show() throws Exception
{
System.out.println("\nEnter the Number of rows:");
n=Integer.parseInt(br.readLine());
for(i=1;i<=n;i++)
{
x=1;
for(j=0;j< 2*i-y;j++)
{
if (j >=i)
x=x/2;
System.out.print(x);
if(j< i)
x=x*2;
}
Also Read: Computer Teacher in Burdwan
System.out.println();
}
}
public static void main(String args[])throws Exception
{
NumberPattern ob=new NumberPattern();
ob.show();
}
}
Related Post: BlueJ Programs On Pattern
No comments:
Post a Comment