Saturday, April 22, 2017

Pattern On Numbers Using Nested Loop



To print the given below pattern

0
0 1
0 2 4
0 3 6 9
0 4 8 12 16
0 5 10 15 20 25
0 6 12 18 24 30 36
0 7 14 21 28 35 42 49
0 8 16 24 32 40 48 56 64
0 9 18 27 36 45 54 63 72 81

Program is as follows:

class B
{
 int i,j,x;
public void show()
{
 for(i=0;i< 10;i++)
{
 System.out.print("0 ");
x=i;
for(j=0;j< i;j++)
{
 System.out.print(x + " ");
x=x+i;
}
System.out.println();
}
}
public static void main(String args[])
{
 B ob=new B();
ob.show();
}
}

Related PostBlueJ Programs On Pattern

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner