如何修复此java错误-$javac loginaSignment.java
我试图运行下面的代码,但是,我得到了这个错误。 我真的不知道遗漏了什么: 这里是错误 java:36:错误:找不到符号 if(pWord[passCounter].equals(enteredpassword)){ ^ 符号:变量输入密码 位置:类登录签名 2个错误如何修复此java错误-$javac loginaSignment.java,java,Java,我试图运行下面的代码,但是,我得到了这个错误。 我真的不知道遗漏了什么: 这里是错误 java:36:错误:找不到符号 if(pWord[passCounter].equals(enteredpassword)){ ^ 符号:变量输入密码 位置:类登录签名 2个错误 这是密码 import java.util.Scanner; public class LoginAssignment { static Scanner input = new Scanner(System.in); pub
这是密码
import java.util.Scanner;
public class LoginAssignment {
static Scanner input = new Scanner(System.in);
public static void main(String[] args){
String[] uName = {"Sosman","Msmith", "Rjoe"};
String[] pWord = {"P4word1", "987654", "cat234"};
String enteredUsername;
System.out.println("Enter your username");
System.out.println("Available users: Sosman, Msmith, Rjoe");
enteredUsername = input.nextLine();
String enteredPassword;
System.out.println("Enter your password");
System.out.println("Available passwords: P4word1, 987654 , cat234");
enteredPassword = input.nextLine();
int userLength = uName.length;
int userCounter;
int userTest = 0;
int userCorrect = -1;
for(userCounter = 0; userCounter < userLength; userCounter++){
if(uName[userCounter].equals(enteredUsername)){
userTest =1;
userCorrect = userCounter;
}
}
int passLenght = pWord.length;
int passCounter;
int passTest = 0;
int passCorrect = -2;
for(passCounter = 0; passCounter < passLength; passCounter++){
if(pWord[passCounter].equals(enteredpassword)){
passTest =1;
passCorrect = passCounter;
}
}
if((userTest== 0|| passTest == 0) ||(userCorrect !=passCorrect))
System.out.println("Username not fourd or password in incorrect");
if(passTest == 1&& userTest == 1&& userCorrect == passCorrect)
System.out.println("You are logged in as: " + uName[userCorrect]);
}
}
import java.util.Scanner;
公共类登录签名{
静态扫描仪输入=新扫描仪(System.in);
公共静态void main(字符串[]args){
字符串[]uName={“Sosman”、“Msmith”、“Rjoe”};
字符串[]pWord={“P4word1”、“987654”、“cat234”};
输入的字符串名;
System.out.println(“输入您的用户名”);
System.out.println(“可用用户:Sosman、Msmith、Rjoe”);
enteredUsername=input.nextLine();
字符串输入密码;
System.out.println(“输入密码”);
System.out.println(“可用密码:P4word1、987654、cat234”);
enteredPassword=input.nextLine();
int userLength=uName.length;
int用户计数器;
int userTest=0;
int userCorrect=-1;
对于(userCounter=0;userCounter
代码中的错误有:
for
中,您键入了passLength
而不是passLength
。这只是一个打字错误,我建议您更改变量的名称,因为正确的拼写是passLength
if
中,您使用了enteredpassword
而不是enteredpassword
,因此出现了另一个打字错误enteredpassword
在该上下文中不作为变量存在。但是enteredpassword
作为变量存在。请注意大小写。无论如何,我强烈建议您使用IDE来编写Java代码,这样会更容易获得错误并修复它们。其中有很多错误,一些好的错误也是免费的,比如eclipse(我用于工作)和IntelliJ(社区版)。试试看。