reading input till EOF in java

后端 未结 10 630
后悔当初
后悔当初 2020-12-09 06:35

In C++ if I wish to read input till the EOF I can do it in the following manner

while(scanf(\"%d\",&n))
{
    A[i]=n;
    i++;
}

I can

10条回答
  •  無奈伤痛
    2020-12-09 06:42

    The only thing that really works for me (you don't even have to create a file)

    Scanner read = new Scanner(System.in);
    String cadena;
    boolean cond = true;
    int i =0;
    while (cond){
        cadena = read.nextLine();
        if(cadena.isEmpty())
            cond = false;
    }
    

提交回复
热议问题