-
Notifications
You must be signed in to change notification settings - Fork 220
/
SimpleCalculator.java
42 lines (42 loc) · 1.53 KB
/
SimpleCalculator.java
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
import java.util.Random;
import java.util.Scanner;
public class SimpleCalculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number: ");
Float y = sc.nextFloat();
System.out.println("Enter the second number: ");
Float z = sc.nextFloat();
int choice;
do {
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. Generate Random Number");
System.out.println("6. Exit");
System.out.println("Enter Your Choice: ");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("The Addition is: " + (y+z));
break;
case 2:
System.out.println("The Subtraction is: " + (y-z));
break;
case 3:
System.out.println("The Multiplication is: " + (y*z));
break;
case 4:
System.out.println("The Division is: " + (y/z));
break;
case 5:
Random generateRandom = new Random();
System.out.println("This Function will generate you a random value: ");
System.out.println(generateRandom.nextFloat(5));
default:
break;
}
}while(choice!=6);
}
}