Java Scanner - 如何检查密码输入是否正确?

时间:2017-09-16 11:59:38

标签: java java.util.scanner

我想检查密码是否使用Java中的Scanner正确输入。

我尝试使用此代码:

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:");

        }
    }
}

1 个答案:

答案 0 :(得分:-1)

更改

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text" /> <xsl:template match="@*|node()"> <xsl:apply-templates select="node()|@*" /> </xsl:template> <xsl:template match="xs:complexType[@name]"> <xsl:variable name="fileName" select="concat('target/',@name,'.txt')" /> <xsl:result-document href="{$fileName}"><xsl:value-of select="$fileName"/></xsl:result-document> </xsl:template> </xsl:stylesheet>

if (pw != pwEnter) {

看看这个问题:How do I compare strings in Java?