【发布时间】:2015-11-01 19:04:40
【问题描述】:
我想要验证:仅输入数字,小时必须
int total; //Total Minutes
String time; //Input from keyboard
final Scanner T = new Scanner(System.in);
System.out.print("Enter the time in HH:MM :");
time = T.next();
//Get the value before the ':'
int hour = Integer.parseInt(time.substring(0, time.indexOf(':')));
//Get the value after the ':'
int minute =Integer.parseInt (time.substring((time.indexOf(':') + 1), time.length()));
//Formula of the calculation
total = hour * 60 + minute;
//Display the final value
System.out.println( time +" is " + total + " minutes.");
【问题讨论】:
-
你不会想要现在 24:53 的时间吧?那么为什么
-
对不起
标签: java validation input