Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Multiplication program

  1. #1
    Junior Member
    Join Date
    May 2012
    Thanked 0 Times in 0 Posts

    Default Multiplication program

    Hi guys! I have created a program that is designed to ask students multiple equation questions. The program will only be designed to ask single digit numbers. I have managed to create the questions and a random number generator, but i want this program to constantly loop, any ideas on how to implement a loop?

    Heres my code:
    import java.util.Scanner;
    public class SubtractionQuiz {
    public static void main (String[] args) {
    int number1 = (int) (Math.random() * 10);
    int number2 = (int) (Math.random() * 10);
    System.out.println("What is" + number1 + " * " + number2 + "?");
    Scanner input = new Scanner(System.in);
    int answer = input.nextInt();
    if (number1 * number2 == answer)
    System.out.println("You are correct!");

    Thanks in advance!

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,393 Times in 2,347 Posts

    Default Re: Multiplication program

    What kind of looping statements do you know about? Which one do you want to use?
    When do you want to exit the loop? On user request or after a number of tries?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 832 Times in 772 Posts
    Blog Entries

    Default Re: Multiplication program

    Please read the forum rules - double posting is not allowed. I am locking this thread - please keep discussions to your other thread
    Multiplication program Loop

Similar Threads

  1. Multiplication program Loop
    By PhilThomspon in forum Loops & Control Statements
    Replies: 7
    Last Post: May 6th, 2012, 03:29 PM
  2. multiplication of polynomials method functionality
    By bradoz in forum Object Oriented Programming
    Replies: 1
    Last Post: March 27th, 2012, 02:07 AM
  3. Having problem in matrix multiplication....
    By sidhant in forum Java Theory & Questions
    Replies: 5
    Last Post: March 17th, 2011, 01:41 PM
  4. Recursive multiplication and Karatsuba
    By jsp01 in forum Algorithms & Recursion
    Replies: 0
    Last Post: March 14th, 2011, 02:04 AM
  5. Multiplication code
    By bomboy in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 5th, 2011, 01:25 AM