我目前正在從java中進行任何練習,你會發現自午夜以來的秒數。Java字符串連接到整數算術
當用前面的字符串打印計算秒數時,它似乎在使用字符串進行進一步計算。無論結果如何,無論我如何命令它給我不同的錯誤結果,就好像我刪除了「自午夜以來的秒數」字符串,它給了我正確的結果。我括號,以確保它的下面PEMDAS,但我不明白的事情怎麼說串正在改變
String hour, minute, second;
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String theTime = sdf.format(cal.getTime()).toString();
hour = theTime.substring(0,2);
minute = theTime.substring(3,5);
second = theTime.substring(6,8);
int intHour = Integer.parseInt(hour);
int intMinute = Integer.parseInt(minute);
int intSecond = Integer.parseInt(second);
System.out.println("Seconds since midnight: " + (intHour * 3600) + (intMinute * 60) + intSecond);
System.out.println("Seconds since midnight: " + intSecond + (intMinute*60) + (intHour*3600));
+1「HOOOOLD IT RIGHT THERE」 – eqb