Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: Lu Liu
- * Date: 3/23/2016
- * Course Number: CSC-112
- * Course Name: Intermediate Topics in Java Programming
- * Email: lliu0001@student.stcc.edu
- *
- * Assignment: HW # 10
- * Programe Description:
- * MyProgrammingLab assignment for Chapter 12 Project 71039
- * Write a program that prompts the user to read two integers and displays their sum
- */
- package MyProgramming;
- import java.util.*;
- public class TestNumber {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n1 = 0;
- int n2 = 0;
- while (true) {
- try {
- System.out.print("Enter first integer: ");
- n1 = sc.nextInt();
- break;
- } catch (InputMismatchException e) {
- System.out.println("Please enter an integer.");
- sc.nextLine();
- }
- }
- while (true) {
- try {
- System.out.print("Enter second integer: ");
- n2 = sc.nextInt();
- break;
- } catch (InputMismatchException e) {
- System.out.println("Please enter an integer.");
- sc.nextLine();
- }
- }
- System.out.println("The sum of " + n1 + " and " + n2 + " is " + (n1 + n2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement