View Single Post
Old 11-14-2004, 02:17 PM   #1 (permalink)
crackpot
Junkie
 
Location: Montreal
Total beginner Java questions...

I've just started learning Java this week. Feel free to laugh, I can take it.

So, I'm doing this 9x multiplication table, as an exercise:

class table9x9
{
public static void main(String args[])
{
for(int x = 1; x <= 9; x ++)
{ System.out.print(x + "\t");
for(int y = 2; y <= 9; y ++)
{
System.out.print(x * y + "\t");
}
System.out.println();
}
}
}


Questions... 1) Is this the most elegant way to achieve the results? E.g. I'm not sure about initializing y as 2 (although it does the job)...

2) Is it better to initialize x & y outside of the for loops? Or is that irrelevant?

3) When I run this, the single digit "answers", top-left of the table, do not align evenly. I cannot for the life of me understand why not!

4) My dos shell "copy" button: how do I enable that? Y'know, so I can show the result.

Any help would be appreciated. I've gotta lot of learning to do. Thanks!
crackpot is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62