Advertisement
SensaBG

DOKATO

Jul 3rd, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. package WorkingWithAbstraction;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10.     // Read commands from the scanner each on a new line until the command equals "End"
  11.        
  12.         // In other words:
  13.        
  14.         // Read Strings from the console until the user enters "End"
  15.        
  16.        
  17.  
  18.         // Option 1:
  19.        
  20.  
  21.         String command1 = scanner.nextLine();
  22.         while(!"End".equals(command1)){
  23.  
  24.  
  25.             command1 = scanner.nextLine();
  26.         }
  27.  
  28.        
  29.         // Option 2:
  30.  
  31.  
  32.         String command2;
  33.         while(!"End".equals(command2 = scanner.nextLine())){
  34.  
  35.  
  36.         }
  37.        
  38.        
  39.         // Option 2 for beginners:
  40.  
  41.         String command3 = "";
  42.         while(!"End".equals(command3 = scanner.nextLine())){
  43.  
  44.  
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement