2个错误:表达式[Java]的非法开始
我还没有完成这个,但如果我已经有一个错误,就没有任何进展的意义。这是我的密码2个错误:表达式[Java]的非法开始,java,Java,我还没有完成这个,但如果我已经有一个错误,就没有任何进展的意义。这是我的密码 public static void main(String[] args) { Scanner inputDevice = new Scanner(System.in); System.out.print("Please enter the name of student ==> "); studentName = inputDevice.nextInt(); inputDevi
public static void main(String[] args)
{
Scanner inputDevice = new Scanner(System.in);
System.out.print("Please enter the name of student ==> ");
studentName = inputDevice.nextInt();
inputDevice.nextLine();
System.out.printIn("Enter the mark for student "+ studentName " out of 65 ==> ");
studentMark = inputDevice.nextInt();
inputDevice.nextLine();
}
第一个错误:“)”应为
System.out.printIn(“在65个学生中输入学生“+studentName”的分数==>”代码>
第二个错误:表达式的开头非法
System.out.printIn(“在65个学生中输入学生“+studentName”的分数==>”代码>
我是新来的lol。我不明白为什么我的第二次打印会给我一个错误替换这个
System.out.printIn("Enter the mark for student "+ studentName " out of 65 ==> ");
与
我认为您没有像应该的那样声明变量。
扫描仪输入=新扫描仪(System.in)
String studentName=inputDevice.nextLine();
int studentMark=inputDevice.nextInt()代码>基本上,这里几乎所有的事情都是错的
问题#1-第3行
studentName = inputDevice.nextInt();
您没有正确声明studentName
。当您想要一个名称(String
)时,您还试图获取一个int
。该行应改为:
String studentName = inputDevice.nextLine();
问题#2-第4行
inputDevice.nextLine();
这条线在这里干什么?您没有将输入分配给任何对象。把这条线完全去掉
问题#3-第5行
System.out.printIn("Enter the mark for student "+ studentName " out of 65 ==> ");
您缺少一个+
。这一行应改为:
System.out.printIn("Enter the mark for student "+ studentName +" out of 65 ==> ");
第4期-第6行
studentMark = inputDevice.nextInt();
同样,您没有正确声明该变量。应该是:
int studentMark = inputDevice.nextInt();
问题#5-第7行
inputDevice.nextLine();
就像第二期一样,这一行一无所获。移除它
摘要
您的代码(可能)应改为如下所示:
Scanner inputDevice = new Scanner(System.in);
System.out.print("Please enter the name of student ==> ");
String studentName = inputDevice.nextLine();
System.out.println("Enter the mark for student "+ studentName + " out of 65 ==> ");
int studentMark = inputDevice.nextInt();
studentName
应该是String studentName
,studentMark
应该是int studentMark
,否?此外,您从未将nextLine()
的返回值分配给任何东西……哇,7行中有5行有故障或不需要。我给你写了一份所有问题的清单,希望你能理解并解决这些问题,更重要的是,防止将来发生这些问题。但是,下次,请自己喝杯咖啡,仔细阅读您的代码(以及错误消息),在这里询问之前,自己确定其中一些问题。
Scanner inputDevice = new Scanner(System.in);
System.out.print("Please enter the name of student ==> ");
String studentName = inputDevice.nextLine();
System.out.println("Enter the mark for student "+ studentName + " out of 65 ==> ");
int studentMark = inputDevice.nextInt();