以下是翻译好的内容: 以下描述了Scanner方法nextLine的返回类型和参数。

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

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

  1. public String nextLine()

这个公共方法没有参数,返回一个字符串。

英文:

You can take a look at the javadoc:

  1. public String nextLine()

The public method has no parameters and return a String.

答案2

得分: 0

Scanner.nextLine()没有参数,返回一个字符串。

考虑以下代码:

  1. import java.util.Scanner;
  2. public class ScannerEx {
  3. public static void main (String [] args) {
  4. Scanner scanner = new Scanner(System.in);
  5. String input = scanner.nextLine();
  6. System.out.println(input);
  7. }
  8. }

如果我输入:

  1. foobar

它将打印:

  1. foobar

如果它是void类型,那么它将不返回任何内容。不仅不会有输出,还会出现编译错误。

英文:

Scanner.nextLine() has no parameters, and returns a String.

Consider this code:

  1. import java.util.Scanner;
  2. public class ScannerEx {
  3. public static void main (String [] args) {
  4. Scanner scanner = new Scanner(System.in);
  5. String input = scanner.nextLine();
  6. System.out.println(input);
  7. }
  8. }

If I enter:

  1. foobar

It will print

  1. foobar

If it was void, then it would return nothing. Not only would there be no output, but there would be a compilation error.

huangapple
  • 本文由 发表于 2020年9月26日 02:19:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/64069453.html
匿名

发表评论

匿名网友

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

确定