英文:
Which of the following describes the return type and parameters of the Scanner method nextLine?
问题
以下是翻译好的内容:
问题是:下面哪个描述了Scanner方法nextLine的返回类型和参数?
我相当确定nextLine没有参数。我不确定的是返回类型是String还是void。哪个是正确的?
英文:
The question is: Which of the following describes the return type and parameters of the Scanner method nextLine?
I am pretty sure there are no parameters for nextLine. What I'm not sure of is if the return type is a String or void. Which one is it?
答案1
得分: 1
你可以查看一下javadoc:
public String nextLine()
这个公共方法没有参数,返回一个字符串。
英文:
You can take a look at the javadoc:
public String nextLine()
The public method has no parameters and return a String.
答案2
得分: 0
Scanner.nextLine()
没有参数,返回一个字符串。
考虑以下代码:
import java.util.Scanner;
public class ScannerEx {
public static void main (String [] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
System.out.println(input);
}
}
如果我输入:
foobar
它将打印:
foobar
如果它是void类型,那么它将不返回任何内容。不仅不会有输出,还会出现编译错误。
英文:
Scanner.nextLine()
has no parameters, and returns a String.
Consider this code:
import java.util.Scanner;
public class ScannerEx {
public static void main (String [] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
System.out.println(input);
}
}
If I enter:
foobar
It will print
foobar
If it was void, then it would return nothing. Not only would there be no output, but there would be a compilation error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论