Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java登录错误,无法解析为变量_Java_Variables_Login - Fatal编程技术网

Java登录错误,无法解析为变量

Java登录错误,无法解析为变量,java,variables,login,Java,Variables,Login,我正在为一个java程序构建一个登录系统,该程序将计算某些商店的员工工资。 在我继续之前,我完全知道这不是最安全的登录方式,所以请不要尝试解释,因为我知道。 我的代码如下 public class project15 { public static void main(String[] args); { String store = store501; String stroePin = 1468dty; String personalPin = abc123; String inputSt

我正在为一个java程序构建一个登录系统,该程序将计算某些商店的员工工资。 在我继续之前,我完全知道这不是最安全的登录方式,所以请不要尝试解释,因为我知道。 我的代码如下

public class project15 
{
public static void main(String[] args);
{ 
String store = store501;
String stroePin = 1468dty;
String personalPin = abc123;
String inputStore;
String inputPin;
String inputPersonal
inputStore = JOptionPane.showInputDialog("please enter the store number");
inputPin = JOptionPane.showInputDialog("please enter the stores unique ID");
inputPersonal = JOptionPane.showInputDialog("please enter your persoanl ID");
if (inputStore==store && inputPin==stroePin && inputPersonal==personalPin){
System.out.println("correct information");
}
else 
{
System.out.println("incorrect information");
}
}
}

我在前三个字符串值上得到一个错误,比如说,“store501无法解析为变量。”其他一切似乎都正常工作。谁能指出我哪里出了错,请解释一下,因为我渴望从我可能犯的任何错误中吸取教训。提前感谢,感谢您的反馈

似乎
store501
1468dty
abc123
都是未定义的变量

在使用之前必须定义它们。比如:

String store501 = "some string";
或者您可能希望它们是
字符串
。在这种情况下:

String store =  "store501"; // Strings are between ""
阅读或中有关
字符串的更多信息

记住:

要比较
字符串
请使用:

str1.equals(str2)
不是


创建字符串时,请阅读此“”

,该字符串需要用

将代码更改为:

String store = "store501";
String stroePin = "1468dty";
String personalPin = "abc123";

如果它们是字符串变量,则应将它们放在“”中。您可以通过以下方式进行操作:

String store = "store501";
String stroePin = "1468dty";
String personalPin = "abc123";
或:


你的程序中有不止一个错误。首先,其他人都说要声明字符串常量。但是还有一个错误

您正在使用==来比较字符串。Java表达式a==b比较两个变量,如果两个变量引用同一个对象,则返回true。它不会比较对象以查看它们是否具有相同的值

您的程序可以设置personalPin=“abc123”;当提示输入inputPersonal时,用户可以输入abc123,然而personalPin和inputPersonal可能引用两个不同的字符串对象,这两个对象恰好具有相同的值。也就是说,即使两个字符串都是“abc123”,personalPin==inputPersonal也可能为false

解决方法是使用String.equals()函数比较字符串的内容:


personalPin.equals(inputPersonal)

您需要加引号:
String store=“store501”“字符串文字由零个或多个用双引号括起来的字符组成”
StringLiteral:“StringCharacters”
fyi,您在:stropepin->storePin“请输入您的个人ID”->“请输入您的个人ID”中有一个打字错误,并且您在比较字符串时使用的是
str1==str2
而不是
str1.equals(str2)
我刚刚完成了这项工作,现在如果我输入了正确或不正确的信息,屏幕上会显示“不正确的信息”。永远不要将字符串与==”进行比较。您应该始终使用.equals()。我将为您更新上面的代码我刚刚完成了这项工作,现在如果我键入正确或不正确的信息字符串与
相等值进行比较,我会在屏幕上打印“错误信息”
请参见编辑。谢谢,我刚刚通读了这是非常有用的信息,只是想知道如果有人输入了10次错误的信息,有没有办法关闭程序?请尝试
while
for
循环。还有一次,你可以在
String store = "store501";
String stroePin = "1468dty";
String personalPin = "abc123";
String store = "store501";
String stroePin = "1468dty";
String personalPin = "abc123";
String store;
String stroePin;
String personalPin;
store="store501";
stroePin="1468dty";
personalPin="abc123";