我尚未完成此操作,但是如果我已经有错误,则没有任何进展。这是我的代码..
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("Enter the mark for student "+ studentName " out of 65 ==> ");
第二错误:表达式
非法开始 System.out.printIn("Enter the mark for student "+ studentName " out of 65 ==> ");
我很新。我不明白为什么我的第二张打印给我错误
基本上,几乎所有内容在这里是错误的。
问题#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();
就像第2期一样,这条线一无所获。删除它。
摘要
您的代码应该(可能(这样读取:
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();
替换此
System.out.printIn("Enter the mark for student "+ studentName " out of 65 ==> ");
System.out.printIn("Enter the mark for student "+ studentName +" out of 65 ==> ");
我认为您没有按照应有的声明变量。扫描仪输入= new Scanner(System.in(;
String studentName = inputDevice.nextLine();
int studentMark = inputDevice.nextInt();