如何显示弹出的内容

时间:2016-10-14 15:52:44

标签: java time printing calculator clock

我正在尝试使用秒数制作程序,然后在午夜之后弹出时间。为了做到这一点,我写了下面的代码,虽然我不能让它打印时间。我可以在控制台中显示它,但我宁愿弹出它。有人能指出我正确的方向吗?感谢

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");
}

}

1 个答案:

答案 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";
}