2017-09-16 91 views
-1

我想檢查密碼是否用Java中的Scanner正確輸入。Java掃描儀 - 如何檢查密碼輸入是否正確?

我試着用這個代碼:

import java.util.Scanner; 

public class test { 

    public static void main(String[] args) { 

     System.out.println("Please enter your username:"); 
     Scanner username = new Scanner(System.in); 
     System.out.println("Hello " + username.nextLine() + ", please authenticate using your password:"); 
     Scanner password = new Scanner(System.in); 
     String pw = "test"; 
     String pwEnter = password.nextLine(); 
     if (pw != pwEnter) { 
      System.out.println("Sorry, you don't have access to the System."); 
     } else { 
      System.out.println("Thank you for authenticating, you can proceed with:"); 

     } 
    } 
} 

回答