public class MultiplicationTable {
public static void main (String[]a){
int[] x;
x = new int[10];
int i;
int n=0;
for (i=0;i
Yes you can! You can use String.format
to add zero padding to your output.
Example:
String.format("%05d", 2)
would produce 00002
.
Some improvement on the current code:
I'm not sure why you intend to store the numbers inside an array (for practice purpose maybe), but that is not necessary as it goes from 1 to 10 anyway. Though if you want to do that, you don't need both i
and n
.
for (i=0; i
Secondly, I'm sure you realize that you have a lot of duplicate code, and it's quite sequential. You can do that using 2 nested for loops, instead of having 10 single loops:
for (int row = 1; row <= 10; row++) {
for (int col = 1; col <= 10; col++)
System.out.print(String.format("%03d", row * col));
System.out.println();
}