public class Enshu0112 {
	public static void main(String[] args) {
		System.out.println("Multiplication table");
		System.out.println("\t|  1  2  3  4  5  6  7  8  9"); //First heading line
		System.out.println("----+------------------------------------");
		for (int i = 1; i < 10; i++) { //Vertical loop
			System.out.printf("%3d |", i);
			for (int j = 1; j < 10; j++) { //Horizontal loop
				System.out.printf("%3d", (j*i)); //Align the display digits so that they are vertically aligned
			}
			System.out.println(); //Insert line break
		}
	}
}
When I tried to align the heading line vertically in the form of \ t1 \ t \ 2 ..., it was left-aligned, so I decided to adjust it with a half-width space.
Anyway, multiplication table is basic in practice of loop processing.
Recommended Posts