如何打印正确的用户名和密码,而不显示其他insde。 [英] How to print the correct username and password and not showing the other insde.

查看:64
本文介绍了如何打印正确的用户名和密码,而不显示其他insde。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我正确输入密码和用户名时,也会出现USER NOT RECOGNIZED。它应该只是CORRECT USERNAME和PASSWORD。

我应该怎么做?

和3次尝试仅用于用户名和密码,并且每当其中一个错误时,用户不会被识别出来并且密码不正确。这就是为什么我有循环。

这是我的代码。



我试过的:



when i enter the password and username correctly the USER NOT RECOGNIZED also comes out. it should only be CORRECT USERNAME AND PASSWORD ONLY.
what should i do ?
and 3 attempts only for username and password and also whenever one of them is wrong the user not recognized will come out and incorrect password. that is why i have looping.
this is my code.

What I have tried:

public static void main(String[]args)
    {     
    String inputUsername = "none";
    String inputPassword = "none";
    String userName = "informatics";
    String password = "1234";
    int count = 0;
    
while (count < 3 && ((!inputUsername.equals(userName)) || (!inputPassword.equals(password))))
{
    Scanner input1 = new Scanner(System.in);
    System.out.println("USERNAME:");
    inputUsername = input1.next(); 
    Scanner input2 = new Scanner(System.in);
    System.out.println("PASSWORD:");
    inputPassword = input2.next();
    {
     if(count < 3)
    {
            if (inputPassword.equals(password))
            {
                System.out.println("User not Recognized");
            }
            else if(inputUsername.equals(userName))
         {
          System.out.println("Invalid Password");
         }
     }
    count++;  
   }
}
if ((inputUsername.equals(userName)) && (inputPassword.equals(password)))
    System.out.println("Correct Username && Password: Welcome to this Application!");
else
    System.out.println("Intruder Detected!");
    }
}

推荐答案

嗯。

Um.
if (inputPassword.equals(password))
    {
    System.out.println("User not Recognized");
    }
else if(inputUsername.equals(userName))
    {
    System.out.println("Invalid Password");
    }

因此,如果输入正确的名称或密码,用户将无法识别?

您的意思是:

So the user is not recognised if he enters the correct name or password?
Did you mean:

<pre>if (!inputPassword.equals(password))
    {
    System.out.println("User not Recognized");
    }
else if(!inputUsername.equals(userName))
    {
    System.out.println("Invalid Password");
    }


引用:

当我输入密码时和用户名正确的USER NOT RECOGNIZED也出来了。它应该只是CORRECT USERNAME和PASSWORD。

when i enter the password and username correctly the USER NOT RECOGNIZED also comes out. it should only be CORRECT USERNAME AND PASSWORD ONLY.



首先,你应该重读你的代码并注意细节。


First of all you should reread your code and pay attention to details.

if (inputPassword.equals(password))
{
    System.out.println("User not Recognized");
}
else if(inputUsername.equals(userName))
{
    System.out.println("Invalid Password");
}



此密码在密码正确时打印用户无法识别,在用户正确时打印无效密码。



学会正确缩进代码,显示其结构,有助于阅读和理解。它还有助于发现结构错误。


This code prints "User not Recognized" when the password is correct, and "Invalid Password" when user is correct.

Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.

public static void main(String[]args)
{
  String inputUsername = "none";
  String inputPassword = "none";
  String userName = "informatics";
  String password = "1234";
  int count = 0;

  while (count < 3 && ((!inputUsername.equals(userName)) || (!inputPassword.equals(password))))
  {
    Scanner input1 = new Scanner(System.in);
    System.out.println("USERNAME:");
    inputUsername = input1.next();
    Scanner input2 = new Scanner(System.in);
    System.out.println("PASSWORD:");
    inputPassword = input2.next();
    {
      if(count < 3)
      {
        if (inputPassword.equals(password))
        {
          System.out.println("User not Recognized");
        }
        else if(inputUsername.equals(userName))
        {
          System.out.println("Invalid Password");
        }
      }
      count++;
    }
  }
  if ((inputUsername.equals(userName)) && (inputPassword.equals(password)))
    System.out.println("Correct Username && Password: Welcome to this Application!");
  else
    System.out.println("Intruder Detected!");
}
}



专业程序员的编辑器具有此功能以及其他功能,例如括号匹配和语法高亮。

Notepad ++ Home [ ^ ]

ultraedit [ ^ ]


这篇关于如何打印正确的用户名和密码,而不显示其他insde。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆