Advertisement
Spocoman

02. Password

Aug 28th, 2024
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Password {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String username = scanner.nextLine();
  7.         String password = scanner.nextLine();
  8.         String input = "";
  9.  
  10.         while (true) {
  11.             input = scanner.nextLine();
  12.             if (input.equals(password)) {
  13.                 System.out.println("Welcome " + username + '!');
  14.                 break;
  15.             }
  16.         }
  17.     }
  18. }
  19.  
  20. ИЛИ:
  21.  
  22. import java.util.Scanner;
  23.  
  24. public class Password {
  25.     public static void main(String[] args) {
  26.         Scanner scanner = new Scanner(System.in);
  27.         String username = scanner.nextLine();
  28.         String password = scanner.nextLine();
  29.         String input = scanner.nextLine();
  30.  
  31.         while(!input.equals(password)){
  32.             input = scanner.nextLine();
  33.         }
  34.        
  35.         System.out.println("Welcome " + username + '!');
  36.     }
  37. }
  38.  
  39. ИЛИ:
  40.  
  41. import java.util.Scanner;
  42.  
  43. public class Password {
  44.     public static void main(String[] args) {
  45.         Scanner scanner = new Scanner(System.in);
  46.         String username = scanner.nextLine();
  47.         String password = scanner.nextLine();
  48.         String input = "";
  49.  
  50.         while(!(input = scanner.nextLine()).equals(password)){
  51.         }
  52.  
  53.         System.out.println("Welcome " + username + '!');
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement