[英]Importing a scanner class in a method
I have this assignment in school, where I have to import a scanner and write a method. 我在学校有这项作业,我必须在其中导入扫描仪并编写方法。 What am I doing wrong?
我究竟做错了什么?
public static void main(String[] args)
{
applicationDate();
}
public static void applicationDate()
{
Scanner input = new Scanner(System.in);
System.out.println("On what day of the month you applied?");
int day = input.nextInt();
System.out.println("What is the name of the month in wich you applied?");
String month = input.nextLine();
System.out.println("During wich year you applied?");
int year = input.nextInt();
System.out.print("Your application date is" + month + " ", + year + "!");
}
It comes with this error when I compile the thing, EX20.java:27: cannot find symbol 当我编译东西时,它伴随着这个错误,EX20.java:27:找不到符号
print
only takes one String
argument - move the comma inside the String
print
只需要一个String
参数-将逗号移动到String
System.out.print("Your application date is" + month + " ," + year + "!");
^
删除逗号并将其添加在双引号之间,如下所示。
System.out.print("Your application date is" + month + " ,"+ year + "!");
First add import java.util.Scanner;
首先添加
import java.util.Scanner;
to your file. 到您的文件。 As this line is missing you must be getting error as
由于缺少此行,您必定会因为
error: cannot find symbol
Scanner input = new Scanner(System.in);
^
then 然后
Remove extra comma from the last print statement. 从最后一个打印语句中删除多余的逗号。
System.out.print("Your application date is" + month + " ,"+ year + "!");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.