Sunday, December 25, 2016

// // Leave a Comment

Exercise 3.4: Game: Learn Addition

Program that generates two integers under 100 and prompts the user to enter the sum of these two integers.
/**
 *
 * @Author: Aghatise Osazuwa
 * Website: www.cscprogrammingtutorials.com
 */

import java.util.Scanner;

public class Ex03_04 {
    public static void main(String[] args) {
        int number1 = (int)(System.currentTimeMillis() % 100);
 int number2 = (int)(System.currentTimeMillis() / 7 % 100);
        Scanner input = new Scanner(System.in);
        System.out.print("What is " + number1 + " + " + number2 + "? ");
 int answer = input.nextInt();
        System.out.println(number1 + " + " + number2 + " = " + answer + " is " 
                + (number1 + number2 == answer));
    }   
}
Liang Introduction to Java Programming exercise 3.4 solution
Sample run

Click here to see other solutions to Introduction to Java Programming.

0 comments:

Post a Comment


DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately. To get notified of replies or follow-up comments, click the box next to notify me.

Thanks.