Answer:
import java.util.Scanner;
public class TestClock {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter num 1");
double num1 = in.nextDouble();
System.out.println("Enter num 2");
double num2 = in.nextDouble();
System.out.println("enter \"s\" for addition\t \"d\" for difference\t \"p\" for the product\t and \"q\" for the quotient");
char op = in.next().charAt(0);
if(op =='s'||op=='S'){
double sum = num1+num2;
System.out.println("The sum is "+sum);
}
else if(op =='d'||op=='D'){
double diff = num1-num2;
System.out.println("The difference is "+diff);
}
else if(op =='p'||op=='P'){
double prod = num1*num2;
System.out.println("The product is "+prod);
}
else if(op =='q'||op=='Q'){
double quo = num1/num2;
System.out.println("The Quotient is "+quo);
}
}
}
Step-by-step explanation:
- Use Scanner class to receive the two numbers and save in a two variables
- Create a new variable for Operation (op) to store a character
- Request the user to enter a character for the opearation (e.g s=sum, p=product, q=quotient and d=difference)
- Use if/else..if statements to implement the required operation