Advertisement
MrDoyle

9) Switch

Jan 14th, 2021
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4.  
  5.     public static void main(String[]args){
  6.  
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         System.out.println("Please enter a command: ");
  10.         String text = input.nextLine();
  11.  
  12.         switch(text){
  13.             case "start":
  14.                 System.out.println("Machine started");
  15.                 break;
  16.  
  17.             case "stop":
  18.                 System.out.println("Machine stopped");
  19.                 break;
  20.  
  21.             default:
  22.                 System.out.println("Command not recognised:");
  23.  
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement