476179

switchNum

Nov 4th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. package les;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Switch_Num
  6. {
  7.  
  8. public static void main(String[] args)
  9. {
  10. Scanner keyboard = new Scanner(System.in);
  11.  
  12. int num;
  13. System.out.println("enter 1, 2, or 3:");
  14. num = keyboard.nextInt();
  15.  
  16. switch (num)
  17. //switch only works when testing only one value
  18. {
  19. case 1:
  20. System.out.println("you entereed 1, its January");
  21. break;
  22. //break statment ends the program from searching throuhg the switch ststment,
  23. //if no break itll contuinue and execute all following cases after correct one
  24. //break stops from going further
  25.  
  26. case 2:
  27. System.out.println("you entereed 2, its February");
  28. break;
  29.  
  30. case 3:
  31. System.out.println("you entereed 3, its March");
  32. break;
  33.  
  34. default:
  35. System.out.println("you must enter 1, 2 or 3.");
  36. break;
  37. }
  38.  
  39. keyboard.close();
  40.  
  41. }
  42.  
  43. }
Add Comment
Please, Sign In to add comment