ITEC 120 LAB 8 Back to Lab index page

Multiplication tables

You will write Java program that will ask the user to enter two positive integers. Make sure the user enters two positive integers. Your program will then print out a multiplication table using the two numbers they entered.

Sample run:

Program outputs: I will create a multiplication table for you!
Please enter first number:
User inputs: 4
Program outputs: Please enter second number:
User inputs: -6
Program outputs: Please enter second number:
User inputs: 5
Program outputs:

The multiplication table for 4 and 5 is:

   1    2    3    4    5
   2    4    6    8    10
   3    6    9    12   15
   4    8    12   16   20

You'll need to use some nested loops for this assignment. You should use incremental development to solve this problem. First, get two valid integers from the user. Get that to run, then work on the loops to print the multiplication table.

LAB CHALLENGE: For ambitious programmers only! Make your multiplication table properly justified -- in other words, right justify the numbers. So, the table above would look like this:

The multiplication table for 4 and 5 is:

   1    2    3    4    5
   2    4    6    8   10
   3    6    9   12   15
   4    8   12   16   20

Once you have your program working, show your lab to the Peer Instructor to be checked off. The Peer Instructor will run the program.