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.
Please help
Thanks,
Jeff
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?
The comments in your code are not very helpful.
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
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?
Re: I'm new at this and can't figure it out
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();
}