Java 什么是';不是一句话';?
我正在尝试读取一个文件,然后将其打印出来。跳过第一行 这是我的密码Java 什么是';不是一句话';?,java,compiler-errors,Java,Compiler Errors,我正在尝试读取一个文件,然后将其打印出来。跳过第一行 这是我的密码 import java.util.Scanner; import java.io.File; import java.io.*; public class cas{ public static void main(String[] args) { Scanner CL = new Scanner(new File("myBoard.csv")); CL.nextLine; while(CL.hasNext){
import java.util.Scanner;
import java.io.File;
import java.io.*;
public class cas{
public static void main(String[] args) {
Scanner CL = new Scanner(new File("myBoard.csv"));
CL.nextLine;
while(CL.hasNext){
String[] tempAdd = CL.nextLine.split(" ");
for(int i = 0; i<tempAdd.length; i++)
System.out.print(tempAdd[i] + " ");
System.out.println();
}
}
}
这个语句不是应该将指针移动到下一行,而不使用它吗
是的,这是一个方法调用,为什么编译器不捕获另一个CL.nextLine?nextLine不应该执行为:
CL.nextLine();
如果您只写“CL.nextLine”,您已经声明了方法的名称,但这没有任何作用,您必须使用“()”执行该方法。你也必须这样做
CL.hasNext();
nextLine不应该执行为:
CL.nextLine();
如果您只写“CL.nextLine”,您已经声明了方法的名称,但这没有任何作用,您必须使用“()”执行该方法。你也必须这样做
CL.hasNext();
你必须改变-
while(CL.hasNext)
至-
while(CL.hasNext()){
及
至-
您的版本应解释为“语法错误”。您必须更改-
while(CL.hasNext)
至-
while(CL.hasNext()){
及
至-
您的版本应解释为“语法错误”。请参见下文,我在需要时更改了代码。你错过了“()”
CL.nextLine();
while(CL.hasNext()){
字符串[]tempAdd=CL.nextLine().split(“”);
对于(inti=0;i请参见下文,我在需要的地方更改了代码。您缺少“()”
CL.nextLine();
while(CL.hasNext()){
字符串[]tempAdd=CL.nextLine().split(“”);
对于(int i=0;i
这不是方法调用。应按如下方式调用它:
CL.nextLine();
这不是方法调用。应按如下方式调用它:
CL.nextLine();
Java编译器认为nextLine是一个公共类属性(我猜您正在尝试调用nextLine方法,这意味着您应该使用CL.nextLine()),并且由于您不能拥有这样的属性,而不将其分配给变量或此语句(CL.nextLine)无效。Java编译器认为nextLine是一个公共类属性(我猜您正在尝试调用nextLine方法,这意味着您应该使用CL.nextLine()),并且由于您不能拥有这样的属性而不将其指定给变量或此语句(CL.nextLine)中的某些内容无效。您需要使用括号表示方法:
scanner.nextLine(); // nextLine() with brackets->()
while (scanner.hasNext()) { // hasNext() with brackets->()
String[] tempAdd = CL.nextLine().split(" "); // nextLine() with brackets->()
for(int i = 0; i<tempAdd.length; i++)
System.out.print(tempAdd[i] + " ");
System.out.println();
}
scanner.nextLine();//带括号的nextLine()->()
while(scanner.hasNext()){//hasNext()带括号->()
字符串[]tempAdd=CL.nextLine().split(“”;//带括号的nextLine()->()
对于(int i=0;i您需要使用括号表示方法:
scanner.nextLine(); // nextLine() with brackets->()
while (scanner.hasNext()) { // hasNext() with brackets->()
String[] tempAdd = CL.nextLine().split(" "); // nextLine() with brackets->()
for(int i = 0; i<tempAdd.length; i++)
System.out.print(tempAdd[i] + " ");
System.out.println();
}
scanner.nextLine();//带括号的nextLine()->()
while(scanner.hasNext()){//hasNext()带括号->()
字符串[]tempAdd=CL.nextLine().split(“”;//带括号的nextLine()->()
对于(inti=0;iimport java.util.Scanner;
导入java.io.*;
公共类难题{
公共静态void main(字符串[]args){
扫描器CL=null;
试一试{
CL=新扫描仪(新文件(“F:\\large_10000.txt”);
}catch(filenotfounde异常){
e、 printStackTrace();
}
CL.nextLine();
while(CL.hasNextLine()){
字符串[]tempAdd=CL.nextLine().split(“”);
对于(inti=0;iimport java.util.Scanner;
导入java.io.*;
公共类难题{
公共静态void main(字符串[]args){
扫描器CL=null;
试一试{
CL=新扫描仪(新文件(“F:\\large_10000.txt”);
}catch(filenotfounde异常){
e、 printStackTrace();
}
CL.nextLine();
while(CL.hasNextLine()){
字符串[]tempAdd=CL.nextLine().split(“”);
对于(int i=0;iCL.nextLine()
用于方法调用。CL.nextLine()
用于方法调用。如果Scanner
构造函数抛出,则NiceNullPointerException
。代码会故意使用null
s,就像NPE(或更糟)那样。只需声明要抛出的main
方法。如果Scanner
构造函数抛出,则NiceNullPointerException
。代码会故意使用类似NPE(或更糟)的null
方法。只需声明要抛出的main
方法。