扫描仪不读取整个句子 - 扫描仪类的 next() 和 nextLine() 之间的差异
2022-09-01 08:00:07
我正在编写一个程序,允许用户输入他的数据,然后输出它。它的3/4正确,但是当它到达输出地址时,它只打印一个单词,让我们只说“大主教街”中的“大主教”。如何解决此问题?
import java.util.*;
class MyStudentDetails{
public static void main (String args[]){
Scanner s = new Scanner(System.in);
System.out.println("Enter Your Name: ");
String name = s.next();
System.out.println("Enter Your Age: ");
int age = s.nextInt();
System.out.println("Enter Your E-mail: ");
String email = s.next();
System.out.println("Enter Your Address: ");
String address = s.next();
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("E-mail: "+email);
System.out.println("Address: "+address);
}
}