1
用户输入格式为XX/XX/XXXX的日期,并使用分隔符来挑选输入中的整数,但我无法弄清楚如何在不将另一个/放在末尾的情况下获取year变量的输入。我该如何去争取那一年的变数?为什么扫描仪不能在没有/末的情况下选择我的年份变量?
在此先感谢
package formatting_problem;
import java.util.Scanner;
public class DateFormatter {
public static void main(String[] args) {
Integer day = 0;
Integer month = 0;
Integer year = 0;
Integer test = null;
Scanner input = new Scanner(System.in).useDelimiter("/");
System.out.println("Enter a date in the format XX/XX/XXXX to be formatted to Month Day,Year");
while (input.hasNext()){
month = input.nextInt();
day = input.nextInt();
year = input.nextInt();
System.out.println();
}