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
+10.3k Golang : How to check if a website is served via HTTPS
+11.8k Golang : Verify Linux user password again before executing a program example
+9k Golang : Get SPF and DMARC from email headers to fight spam
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+8.3k Useful methods to access blocked websites
+30.4k Golang : How to redirect to new page with net/http?
+11.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+41.2k Golang : How to count duplicate items in slice/array?
+13.6k Golang : Query string with space symbol %20 in between
+5.8k Linux : Disable and enable IPv4 forwarding
+22.7k Golang : Set and Get HTTP request headers example
+8.1k Golang : Tell color name with OpenCV example