Write a program that will read two numbers and an integer code from the keyboard. The value of the integer code should be 1, 2, 3 or 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is not zero, compute the quotient (first divided by second). If the code is not equal to 1, 2, 3 or 4, display an error message. The program is then to display the two numbers, the integer code and the computed result to the screen.
public static void main(String[] args) {
Scanner read = new Scanner (System.in);
int num1, num2, code, sum;
System.out.println("Please enter a number");
num1 = read.nextInt();
System.out.println("please enter second number");
num2 = read.nextInt();
System.out.println("please enter code");
code = read.nextInt();
if(code==1)
{
sum = 1 + 2;
}
if (code==2)
{
sum = 1 - 2;
}
if(code ==4)
{
sum = 1 / 2;
}
else if (code!=1,2,3,4); - I am getting an error and can you tell me if I have code this correctly
{
System.out.println("Print error");
}
can somebody tell if I have use the right code for this problem but I write it as i see it but I can be wrong.