-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_loop.java
More file actions
80 lines (55 loc) · 2.08 KB
/
calc_loop.java
File metadata and controls
80 lines (55 loc) · 2.08 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Java CIS 141
Mohammed Brohi
LOOP LAB */
import java.util.*;
public class Calc {
public static void main(String[] args) {
double number1;
double number2;
char selection;
char choice;
System.out.printf(" A.Addition%n B.Subtraction%n C.Multiplication%n D.Divison%n E.Exit%n");
number1 = 0;
number2= 0;
Scanner console = new Scanner(System.in);
System.out.println("Please Enter selection: ");
selection = console.next().charAt(0);
choice = Character.toUpperCase(selection);
while ( choice != 'E')
{
if(choice == 'A')
{
System.out.println("Please Enter 1st number: ");
number1=console.nextDouble();
System.out.println("Please Enter 2nd number: ");
number2=console.nextDouble();
System.out.printf("%.2f + %.2f = %.2f", number1, number2, (number1 + number2));
}else if(choice == 'B') {
System.out.println("Please Enter 1st number: ");
number1=console.nextDouble();
System.out.println("Please Enter 2nd number: ");
number2=console.nextDouble();
System.out.printf("%.2f + %.2f = %.2f", number1, number2,(number1 - number2 ));
}
else if(choice == 'C') {
System.out.println("Please Enter 1st number: ");
number1=console.nextDouble();
System.out.println("Please Enter 2nd number: ");
number2=console.nextDouble();
System.out.printf("%.2f * %.2f = %.2f", number1, number2, (number1 * number2));
}else if(choice == 'D') {
System.out.println("Please Enter 1st number: ");
number1=console.nextDouble();
System.out.println("Please Enter 2nd number: ");
number2=console.nextDouble();
System.out.printf("%.2f * %.2f = %.2f", number1, number2, (number1 / number2));
}
else
System.out.println("Wrong Selection Please Try again: ");
System.out.println("\n\nPlease Enter selection: ");
selection = console.next().charAt(0);
choice = Character.toUpperCase(selection);
}//end of while
System.out.println("Good-Bye! ");
}//end of main
}//end of class