我对 Java 入门类的部分作业是花时间作为字符串输入,并将其转换(同时舍入到最接近的一刻钟)为双精度,并将其存储在一个数组中。我遇到困难的部分是如何处理从 String 类的 split 方法收到的两个整数。如何将两个整数变成一个双精度以在数组中使用?(所以它就像 hours.minutes 或 5.25)这是我正在处理的程序中的一段代码:
public static double convertClockOutTimes(String clockOut){
double convertedTimeOut = 0;
String time = clockOut;
int hours;
int minutes;
String[]splitFields;
splitFields = time.split(":");
hours = Integer.parseInt(splitFields[0]);
minutes = Integer.parseInt(splitFields[1]);
if (minutes <= 7)
{
minutes = 0;
}
else if (minutes >= 8 || minutes <= 22)
{
minutes = 15;
}
else if (minutes >= 23 || minutes <= 37)
{
minutes = 30;
}
else if (minutes >= 31 || minutes <= 53)
{
minutes = 45;
}
else
minutes = 0;
hours = hours + 1;
convertedTimeOut = //This is where I don't know what to do!!
return convertedTimeOut;
}