如何在UVA在线问题中仅使用Java接受字符串输入?需要详细信息。

huangapple go评论80阅读模式
英文:

How can I take string input for UVA online problem for java only ? Detail information needed

问题

我正在尝试在UVA在线评测问题中使用JAVA处理字符串输入。

像C++一样

while ((s = getchar()) != -1) {
    // 当s等于-1时
}
英文:

I am trying to string input for UVA online judge problem using JAVA.

like C++

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

答案1

得分: 0

import java.util.Scanner;

Scanner scanner = new Scanner(System.in);
System.out.println("Enter a string.");
String str = scanner.nextLine();

Is this what you're looking for? If you're reading from a file,

import java.io.File;

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

Scanner scanner = new Scanner(System.in);
System.out.println("Enter a string.");
String str = scanner.nextLine();

Is this what you're looking for? If you're reading from a file,

import java.io.File;

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

答案2

得分: 0

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

    Scanner stdin = new Scanner(System.in);
    
    while (stdin.hasNextLine()) 
    {
      String line = stdin.nextLine();
      // 进一步操作
    }
英文:

I have solved this using the following

Scanner stdin = new Scanner(System.in);

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

huangapple
  • 本文由 发表于 2020年10月22日 15:22:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64477185.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定