我在学习 Java 时遇到了这个程序:
package com.nathan2055.booksamples;
import static java.lang.System.out;
import java.util.Scanner;
/**
* @author Nathan2055
*/
public class Copycat {
private static Scanner keyboard;
/**
* @param args
*/
public static void main(String[] args) {
keyboard = new Scanner(System.in);
out.println("This program will copy whatever you type.");
out.println("Please enter a phrase:");
String inputPhrase = keyboard.next();
out.println();
out.println(inputPhrase);
}
}
但是有一个问题。如果您运行它并输入一个带有空格的短语,它只会将字符串保存到空格中。我怎样才能让它保存整个字符串?