-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhileArgMethod.java
More file actions
54 lines (43 loc) · 1.72 KB
/
Copy pathWhileArgMethod.java
File metadata and controls
54 lines (43 loc) · 1.72 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
package Methods;
import java.util.Scanner;
public class WhileArgMethod {
public static void main(String[] args) {
calc();
}
static void calc() {
Scanner input = new Scanner(System.in);
while (true) {
System.out.println("\nBasic conditionals.Calculator");
System.out.print("Enter basics.basics.basics.first number: ");
int a = input.nextInt();
System.out.print("Enter second number: ");
int b = input.nextInt();
System.out.println("Choose the operation:");
System.out.println("1.) Addition");
System.out.println("2.) Subtraction");
System.out.println("3.) Multiplication");
System.out.println("4.) Division");
System.out.println("5.) Exit");
System.out.print("Enter your choice: ");
int ch = input.nextInt();
if (ch == 1) System.out.println("Result = " + (a + b));
else if (ch == 2) System.out.println("Result = " + (a - b));
else if (ch == 3) System.out.println("Result = " + (a * b));
else if (ch == 4) {
if (b != 0) System.out.println("Result = " + (a / b));
else System.out.println("Division by zero not allowed.");
}
else if (ch == 5) {
System.out.println("Exiting...");
break;
}
else System.out.println("Invalid choice.");
System.out.print("\nDo you want to continue? (y/n): ");
char cont = input.next().charAt(0);
if (cont == 'n' || cont == 'N') {
System.out.println("Program ended.");
break;
}
}
}
}