Thursday, January 4, 2018

Pattern Of Numbers In BlueJ

To print the following pattern: 
1
3 1
5 3 1
7 5 3 1
9 7 5 3 1 


Here is the code:


class A
{
 int i,j,k;
public void display()
{
 for(i=0;i<=4;i++)
{
 k=i*2+1;
 for(j=0;j<=i;j++)
{
 System.out.print(k + " ");
k=k-2;
}
System.out.println();
}
}
public static void main(String args[])
{
 A obj=new A();
obj.display();
}
}

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner