-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.java
32 lines (24 loc) · 1.05 KB
/
Calculator.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
package com.conditionals;
import java.util.Scanner; //there is need to import scanner class to get input from user
public class Calculator {
public static void main(String[] args) {
System.out.println("Enter Number1 and Number2");
Scanner scanner = new Scanner(System.in);// read input from system.in
int Number1 = scanner.nextInt();// the input you want from user is integer type
int Number2=scanner.nextInt();
System.out.println("Choose Operation:\n 1.Add \n 2.Subtract \n 3.Multiply \n 4.Divide");
int ChooseOperation = scanner.nextInt();
if (ChooseOperation == 1) {
System.out.println("Answer is " + (Number1 + Number2));
} else if (ChooseOperation == 2 && Number1 > Number2) {
System.out.println("Answer is " + (Number1 - Number2));
}
else if (ChooseOperation == 3) {
System.out.println("Answer is " + (Number1 * Number2));
} else if (ChooseOperation == 4 && Number2 != 0) {
System.out.println("Answer is " + (Number1 / Number2));
} else {
System.out.println("Invalid Operation");
}
}
}