-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestion4.java
41 lines (34 loc) · 1.38 KB
/
Question4.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
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
int firstNumber;
System.out.print("Enter your first integer: ");
firstNumber = user_input.nextInt( );
int secondNumber;
System.out.print("Enter your second integer: ");
secondNumber = user_input.nextInt( );
String operator;
System.out.print("Please enter one of these operators = {+,-,*,/}: ");
operator = user_input.next( );
if(operator.equals("+")){
int sum = firstNumber + secondNumber;
System.out.println("The result is: " + sum);
}
else if(operator.equals("-")){
int sub = firstNumber - secondNumber;
System.out.println("The result is: " + sub);
}
else if(operator.equals("*")){
int mult = firstNumber * secondNumber;
System.out.println("The result is: " + mult);
}
else if(operator.equals("/")){
double firstNumberDouble = (double) firstNumber;
double secondNumberDouble = (double) secondNumber;
double division = firstNumberDouble / secondNumberDouble;
System.out.println("The result is: " + division);
}
}
}