reading input till EOF in java

后端 未结 10 662
后悔当初
后悔当初 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:43

    In Java, One way of reading till EOF is:-

         Scanner scan = new Scanner(System.in);    
         while(scan.hasNextLine())   //read until condition is true
         {
            String line = scan.nextLine();
            System.out.println(line);
            i++;
         } 
    

提交回复
热议问题