【问题标题】:How can I take string input for UVA online problem for java only ? Detail information needed我怎样才能为 Java 的 UVA 在线问题输入字符串?需要的详细信息
【发布时间】:2020-10-22 07:22:38
【问题描述】:

我正在尝试使用 JAVA 为 UVA 在线判断问题字符串输入。

像 C++

while(s = getchar()) {
   if(s == EOF)
}

【问题讨论】:

    标签: java arrays user-input readline eof


    【解决方案1】:
    import java.util.Scanner;
    
    Scanner scanner = new Scanner(System.in);
    System.out.println("Enter a string.");
    String str = scanner.nextLine();
    

    这就是你要找的吗?如果您正在读取文件,

    import java.io.File;
    
    Scanner scanner = new Scanner(new File("path.txt"));
    while (scanner.hasNextLine()) {
        String str = scanner.nextLine();
        //...
    }
    

    【讨论】:

      【解决方案2】:

      我已经使用以下方法解决了这个问题

      Scanner stdin = new Scanner(System.in);
      
      while (stdin.hasNextLine()) 
      {
        String line = stdin.nextLine();
        // Further Opera
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-24
        • 2016-05-10
        • 2020-08-05
        相关资源
        最近更新 更多