Why will my switch code not work?


#1

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;

}


#2

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


#3

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


#4

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