我正在尝试使用秒数制作程序,然后在午夜之后弹出时间。为了做到这一点,我写了下面的代码,虽然我不能让它打印时间。我可以在控制台中显示它,但我宁愿弹出它。有人能指出我正确的方向吗?感谢
import javax.swing.JOptionPane;
公共课练习4 {
private static final int MinsInHour = 60;
private static final int SecsInMinute = 60;
public static void main(String[] args) {
String inputseconds = JOptionPane.showInputDialog("How many seconds? <> ");
int seconds = Integer.parseInt(inputseconds);
}
private static String timeConversion(int seconds) {
final int MinsInHour = 60;
final int SecsInMinute = 60;
int minutes = seconds / SecsInMinute;
seconds -= minutes * SecsInMinute;
int hours = minutes / MinsInHour;
minutes -= hours * MinsInHour;
return hours + " hours " + minutes + " minutes " + seconds + " seconds";
JOptionPane.showMessageDialog(hours + " hours " + minutes + " minutes " + seconds + " seconds");
}
}
答案 0 :(得分:0)
return
之后你不能拥有另一个命令。我为你推翻了最后两行。
private static String timeConversion(int seconds) {
final int MinsInHour = 60;
final int SecsInMinute = 60;
int minutes = seconds / SecsInMinute;
seconds -= minutes * SecsInMinute;
int hours = minutes / MinsInHour;
minutes -= hours * MinsInHour;
JOptionPane.showMessageDialog(hours + " hours " + minutes + " minutes " + seconds + " seconds");
return hours + " hours " + minutes + " minutes " + seconds + " seconds";
}