26. Program to display multiplication tables from 1 to 10 using 2d array.
public class MultiplicationTable {
public static void main(String[] args) {
System.out.println("\tMultiplication table: up to 12");
for (int i=1; i<=10; i++) {
for (int j=1; j<=10; j++) {
System.out.print(addSpaces(4, i*j));
}
System.out.print("\n");
}
}
static String addSpaces(int spaces, int n) {
String s="";
for (int i=(""+n).length(); i<spaces; i++)
s+=" ";
return s+n;
}
}
Walang komento:
Mag-post ng isang Komento