我刚刚在HackerRank中为Java传递了一个问题,我不明白如何在scan.nextLine()
之前添加String s = scan.nextLine()
来打印出整个句子。在添加scan.nextLine()
之前,它甚至没有提示我输入,而是跳过了通过的String s
并进入打印。
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
double d = scan.nextDouble();
scan.nextLine();
String s = scan.nextLine();
// Write your code here.
System.out.println("String: " + s);
System.out.println("Double: " + d);
System.out.println("Int: " + i);
}