[Java] Loop processing and multiplication table

Make a multiplication table with a for loop

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 vertical with \ t, it was left-justified.

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

[Java] Loop processing and multiplication table
Loop processing
Java study # 5 (iteration and infinite loop)
[Java] Exception types and basic processing
[Processing × Java] How to use the loop
Java thread processing
Java string processing
Java and JavaScript
XXE and Java
[Java] Multi-thread processing
[Java] Stream processing
java iterative processing
Parallel and parallel processing in various languages (Java edition)
[Processing x Java] Data type and object-oriented programming
I tried to output multiplication table in Java
[Android / Java] Screen transition and return processing in fragments
Getters and setters (Java)
[Java] Thread and Runnable
Java true and false
Link Processing and SQLite
[Java] String comparison and && and ||
Java --Serialization and Deserialization
[Java] Arguments and parameters
Java joins and splitting table cells in Word documents
timedatectl and Java TimeZone
JAVA constructor call processing
[Java] Branch and repeat
Java random, various processing
Java table expression injection
[Java] Variables and types
java (classes and instances)
[Java] Overload and override
java Scanner loop input
[Processing × Java] How to use loop 2 --- Nested structure, coordinate conversion
Study Java # 2 (\ mark and operator)
Java version 8 and later features
Java adds table to PDF
[Java] Difference between == and equals
[Java] Stack area and static area
Java programming (variables and data)
Java encryption and decryption PDF
Java and Iterator Part 1 External Iterator
Java if and switch statements
Common processing and error processing springmvc
Java class definition and instantiation
Apache Hadoop and Java 9 (Part 1)
Output multiplication table with Stream
[Java] About String and StringBuilder
[Java] HashCode and equals overrides
[Java] Stream API --Stream termination processing
[Java] Stream API --Stream intermediate processing
[Java] Timer processing implementation method
☾ Java / Iterative statement and iterative control statement
Create table and add columns
Measured parallel processing in Java
Java methods and method overloads
Understanding Java Concurrent Processing (Introduction)
java Generics T and? Difference
Advantages and disadvantages of Java
java (conditional branching and repetition)
About Java Packages and imports