switch statement: (this can be written as nested if/else statement)
The values in the case clauses must be constants. They must be integers, characters, or enumeration constants.
import java.util.Scanner; public class SwitchTest { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter a single digit: "); int digit = in.nextInt(); switch(digit) { case 0: System.out.println("zero"); break; case 1: System.out.println("one"); break; case 2: System.out.println("two"); break; case 3: System.out.println("three"); break; case 4: System.out.println("four"); break; case 5: System.out.println("five"); break; case 6: System.out.println("six"); break; case 7: System.out.println("seven"); break; case 8: System.out.println("eight"); break; case 9: System.out.println("nine"); break; default: System.out.println("error"); } } }