Java Programming Problem

100
200 202
300 304 308
400 406 412 418
.
.
.
.
900 916 932 ..............1028

I was given this pattern and asked to write a Java program to output this pattern, including the number which weren't given. It was suprisingly hard, but I did it, and I'm proud! Here's the code (with formatting so kindly ruined by Blogger.) Looks so simple, doesn't it?

class Numbers
{
public static void main (String [] args)
{
int row; // controls number increases in the rows
int colm; // controls number increases in the columns

for (row=1; row<=9; row++)
{
for (colm=1; colm<=row; colm++)
{
System.out.printf(" %3d ", 100*row + (colm-1)*((row-1)*2));
}
System.out.print("\n");
}
}
}

No comments:

Post a Comment