如何计算剩余天数

时间:2020-12-29 16:10:31

标签: java

我正在制作一个小程序来为我计算特定分钟数中的年数和天数。例如,它给了我很好的年数,但不是这个数字(1556640)的天数。

'''

import java.util.Scanner;
public class Exercise17 {
    public static void main(String[] args) {
        Scanner n = new Scanner(System.in);
        System.out.println("type");
        int totalMin = n.nextInt();
        int year;
        int totalYears = totalMin / 518400;
        int remaining  = totalYears % 518400;
        int totalDays = remaining / 1440;
        System.out.println(totalYears + " years and " + totalDays + " days");

    }
}

'''

1 个答案:

答案 0 :(得分:0)

去掉整年之后的剩余分钟数应该是:

int remaining  = totalMin - totalYears * 518400;

示例:

int totalMin = 600000;
int totalYears = totalMin / 518400;
int remaining  = totalMin - totalYears * 518400;
int totalDays = remaining / 1440;
System.out.println(totalYears + " years and " + totalDays + " days");

印刷品

<块引用>

1 年零 56 天