-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathifelse.java
More file actions
29 lines (24 loc) · 898 Bytes
/
ifelse.java
File metadata and controls
29 lines (24 loc) · 898 Bytes
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
import java.util.Scanner;
public class ifelse {
static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
float num1, num2;
double total;
char operator;
System.out.print("Enter first number: ");
num1 = s.nextFloat();
System.out.print("Enter second number: ");
num2 = s.nextFloat();
System.out.println("Enter the Operator: + , - , + , / ");
System.out.println("");
total = num1 + num2;
operator = s.next().charAt(0);
if (operator == '+'|| operator == '-' || operator == '*'
|| operator == '/') {
System.out.println("The Answer is: ");
System.out.println(num1+" "+operator+ " "+num2+" = "+" "+total);
} else {
System.out.println("Sorry Wrong input! Please Try Again!");
}
}
}