You should do it with a switch :
public static void main(String args[])
{
System.out.println("Enter 1 to Add, 2 to Subtract, 3 to Divide, or 4 to Multiply");
int x = keyboard.nextInt();
switch(x){
case 1:
System.out.println("Enter an integer");
int num1 = keyboard.nextInt();
System.out.println("Enter another integer");
int num2 = keyboard.nextInt();
System.out.println("The sum of the numbers equals " + (num1+num2));
break;
case 2:
System.out.println("Enter an integer");
num1 = keyboard.nextInt();
System.out.println("Enter another integer");
num2 = keyboard.nextInt();
System.out.println("The sum of the numbers equals " + (num1-num2));
break;
case 3:
System.out.println("Enter an integer");
num1 = keyboard.nextInt();
System.out.println("Enter another integer");
num2 = keyboard.nextInt();
System.out.println("The sum of the numbers equals " + (num1/num2));
break;
case 4:
System.out.println("Enter an integer");
num1 = keyboard.next=Int();
System.out.println("Enter another integer");
num2 = keyboard.nextInt();
System.out.println("The sum of the numbers equals " + (num1*num2));
break;
default:
System.out.print("Error 510038585832857329457294547243344684643734");
break;
}
}
}
2
solved Error: else without if. What went wrong? [closed]