Java : Generate multiplication table example
Putting this here for my own future reference. A simple Java multiplication table generator that I used to teach my kids programming. Adapted from a previous similar Golang tutorial.
Here you go!
package socketloop;
import java.util.Scanner;
public class GenerateMultiplicationTable {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.format("Enter an integer to generate the multiplication table : ");
int i = input.nextInt();
for (int n = 1; n <= 12; n++) {
System.out.format("%d x %d = %d%n", i, n, i * n);
}
}
}
Sample output:
Enter an integer to generate the multiplication table : 12
12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120
12 x 11 = 132
12 x 12 = 144
See also : Golang : Generate multiplication table from an integer example
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+9.1k Golang : Web(Javascript) to server-side websocket example
+4.9k Golang : Issue HTTP commands to server and port example
+21.5k Golang : How to reverse slice or array elements order
+39.7k Golang : Convert to io.ReadSeeker type
+4.8k Python : Convert(cast) bytes to string example
+11.6k Golang : Convert(cast) bigint to string
+9.8k Golang : Test a slice of integers for odd and even numbers
+7.6k Swift : Convert (cast) String to Double
+8.6k Golang : HTTP Routing with Goji example
+9.1k Golang : Play .WAV file from command line
+4.4k Golang : How to pass data between controllers with JSON Web Token
+8.6k Golang : GMail API create and send draft with simple upload attachment example