Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package les;
- import java.util.Scanner;
- public class Switch_Num
- {
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- int num;
- System.out.println("enter 1, 2, or 3:");
- num = keyboard.nextInt();
- switch (num)
- //switch only works when testing only one value
- {
- case 1:
- System.out.println("you entereed 1, its January");
- break;
- //break statment ends the program from searching throuhg the switch ststment,
- //if no break itll contuinue and execute all following cases after correct one
- //break stops from going further
- case 2:
- System.out.println("you entereed 2, its February");
- break;
- case 3:
- System.out.println("you entereed 3, its March");
- break;
- default:
- System.out.println("you must enter 1, 2 or 3.");
- break;
- }
- keyboard.close();
- }
- }
Add Comment
Please, Sign In to add comment