Get input 2 numbers from user and 1 operator [+, -, *, /] and display the calculated result
Answers
Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the first number:");
int a = sc.nextInt();
System.out.print("Enter another number:");
int b = sc.nextInt();
System.out.print("Enter operator:");
char op = (char)System.in.read();
switch(op){
case '+':
System.out.println(a+b);
break;
case '-':
System.out.println(a-b);
break;
case '*':
System.out.println(a*b);
break;
case '/':
System.out.println(a/(float)b);
break;
default:
System.out.println("Invalid operatrion");
break;
}
}
}
Explanation:
SIS, HOW TO COMMENT THE ANSWER IN BRAINY I CLICK ON COMMENT OPTION AND POST IT BUT MY COMMENTS ARE NOT SHOWING TO ME.
Explanation: