public class SwitchCases {

public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("Enter two numbers");
int x = input.nextInt();
int y = input.nextInt();

System.out.println("Choose a random number between 1 and 4: ");
int random = input.nextInt();
double result;
switch (random){
case 1:
result = x + y;
break;
case 2:
result = x - y;
break;
case 3:
result = x * y;
break;
case 4:
result = x / y;
break;
default:
System.out.print("Error! operator is not correct");
return;
}
System.out.printf("%.1f %c %.1f = %.1f", x, random, y, result);
}
}

why is case 4 giving me an error message?

1 answer

apparently y=0
Similar Questions
  1. import java.util.Scanner;public class Initials { public static void main(String[] args) { Scanner input = new Scanner
    1. answers icon 2 answers
  2. import java.util.Scanner;public class main { public static void main(String[] args) { Scanner wins = new Scanner(System.in);
    1. answers icon 0 answers
  3. public class FutureInvestmentValue {public static void main(String[] args) { Scanner input= new Scanner (System.in);
    1. answers icon 5 answers
  4. how do i add prime numbers in this java code:public class PrimeNumbers { public static void main(String[] args) { int[] array =
    1. answers icon 2 answers
more similar questions