reading input till EOF in java

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

    A simple solution would be to use Scanner class.

    See snipet below:

    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
    
            Scanner s = new Scanner(System.in);
            while(s.hasNextLine())
            {
                String line = s.nextLine();
                System.out.println(line);
            }
        }
    }
    

提交回复
热议问题