计算天数和小时
import javax.swing.JOptionPane; //一年等于365*24*60=525600,一天等于24*60=1440 public class Time { public static void main(String[] args){ String input = JOptionPane.showInputDialog(null,"请输入分钟数:","对话框",JOptionPane.QUESTION_MESSAGE); double minute = Double.parseDouble(input); System.out.println(minute + "minutes is approximately " + (int)(minute / 525600) + " years and " + (int)((minute % 525600)/1440)); } }
提示用户输入分钟数然后显示分钟数代表多少年和多少天。为了简化问题,一年为365天。