Why will my switch code not work?

Why will the code below not pull the correct data? Whenever I enter a zip code it doesn’t matter what it begins with it automatically gives the default surcharge.

System.out.println("Please enter your zip code:  ");  

int zip = keyboard.nextInt();

switch (zip) {
case (4) : surcharge=0.05; break;
case (6) : surcharge=0.09; break;
default: surcharge=0.14;break;

}

If the zip code is five digits, how does your program distinguish the first digit?

How would I correct this and make the program distiguish the first digit for the zip code?

If we can assume that all zip codes are five digits, then floor divide by 10000 to get the first digit.

1 Like