英文:
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论