# I'm new at this and can't figure it out

• September 21st, 2010, 01:41 PM
jaheh06
I'm new at this and can't figure it out
My code is this
public class temp
{
public static void main(String[] args)
{

for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= 6; j++)
{
System.out.print((i*j)*4-3 + " ");
}
System.out.println();
}
}
}
I'm getting:
1 5 9 13 17 21
5 13 21 29 37 45
9 21 33 45 57 69
13 29 45 61 77 93

The output should be:
1 5 9 13 17 21
2 6 10 14 18 22
3 7 11 15 19 23
4 8 13 16 20 24

Can't figure out what I'm doing wrong.
Thanks,
Jeff
• September 21st, 2010, 03:00 PM
Norm
Re: I'm new at this and can't figure it out
Can you describe the algorithm that should be used to generate the desired output?
• September 21st, 2010, 03:16 PM
jaheh06
Re: I'm new at this and can't figure it out
I is the row and J is the column.It appears in java that the columns get printed first because that's the inner loop. I'm trying to get it to look like this:
1 5 9 13 17 21
2 6 10 14 18 22
3 7 11 15 19 23
4 8 13 16 20 24
• September 21st, 2010, 03:28 PM
Norm
Re: I'm new at this and can't figure it out
Can you describe the algorithm that should be used to generate the desired output?
• September 21st, 2010, 04:56 PM
Norm
Re: I'm new at this and can't figure it out
• September 22nd, 2010, 08:44 AM
sanz
Re: I'm new at this and can't figure it out
i hope this can help you, i just program it and its look the same with the output of what you want.

for(int i =1; i<=4;i++)
{
for(int j =1; j<=6;j++)
{
System.out.printf("%3d", (i * j) * 4 - 3 );
}
System.out.println();
}