【发布时间】:2017-02-22 17:38:17
【问题描述】:
我有这个分隔符代码:(":|\\s+")。
我想要这样的标志:(":"),但如果我使用它,程序将无法工作 - 它会在第一个问题后停止。
谁能看到我哪里出错了?
import java.util.Scanner;
public class Salary
{
public static void main(String[] args)
{
int hour1, hour2, minute1, minute2, salary;
double totaly, totSalary, totHours, totMinutes, totDecMinutes;
salary = 190;
Scanner scan = new Scanner(System.in);
scan.useDelimiter(":|\\s+");
System.out.println("Write the time when you startet working."
+ "Use the format (hh:mm).");
hour1 = scan.nextInt();
minute1 = scan.nextInt();
System.out.println("Write the time when you stopped working."
+ "Use the formatet (hh:mm).");
hour2 = scan.nextInt();
minute2 = scan.nextInt();
// Counts the number of workinghours.
totHours = (hour2 - hour1);
// Counts the number om workingminutes, decimal number
totMinutes = (minute2 - minute1);
totDecMinutes = totMinutes/60;
// Counts the salary: total hours.
totaly = totHours + totDecMinutes;
totSalary = totaly*salary;
System.out.printf("Din lön för idag blir: %.2f kr.", totSalary);
}
}
【问题讨论】: