-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart1.java
More file actions
46 lines (41 loc) · 1.46 KB
/
Part1.java
File metadata and controls
46 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Name: Adam Mason
* Date: 2/12/2019
* Project Description: Prompt user to enter the left and right operands and display the sum of the two.
*/
import java.util.Scanner;
public class Part1
{
public static void main()
{
while( true )
{
String stringInput = " ";
int left_op = -1, right_op = -1, sum;
Scanner scan = new Scanner( System.in );
char progEnd = ' ';
//Get first operand
System.out.print("Enter a value for the left operand: ");
left_op = scan.nextInt();
//Get second operand
System.out.print("Enter a value for the right operand: ");
right_op = scan.nextInt();
//Add two operands and display sum
sum = right_op + left_op;
System.out.println( left_op + " + " + right_op + " = " + sum );
scan.nextLine();
while( progEnd != 'y' && progEnd != 'n')
{
System.out.print("Run again (Y/N): ");
stringInput = scan.nextLine().toLowerCase();
if( stringInput.length() == 0 )
progEnd = ' ';
else if ( stringInput.length() > 0 )
progEnd = stringInput.charAt(0);
}
if( stringInput.equals("n"))
break;
System.out.println();
}
}
}