我试图理解它的含义以及为什么它是错误的。
import java.util.Scanner;
public class Relevent {
public static void main(String[]args){
Scanner x = new Scanner(System.in);
System.out.println( x.nextline());
}
}
Eclipse IDE 告诉我这是错误的并给出以下消息:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method nextline() is undefined for the type Scanner
at Relevent.main(Relevent.java:9)
最佳答案
写x.nextLine()
怎么样? ? Java 是一种区分大小写的语言。
您必须完全按照其中所写的 API 进行操作。
方法名称 nextline
看起来难以理解/明显,不是吗?因此,Java 编程的最佳实践是以驼峰式大小写形式编写所有名称(final
和 static
变量除外,例如 MY_FINAL_VARIABLE
)。
关于java - Scanner 类型的 nextline() 方法未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37316259/