概述
*2.7(求出年数)编写程序,提示用户输入分钟数(例如十亿)然后显示这些分钟代表多少年和多少天。为了简化问题,假设一年有365天。
下面是一个运行示例:
Enter the number of minutes:1000000000
1000000000 minutes is approximately 1902 years and 214 days
*2.7(Find the number of years) Write a program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number of years and remaining days for the minutes. For simplicity, assume that a year has 365 days.
Here is a sample run:
Enter the number of minutes:1000000000
1000000000 minutes is approximately 1902 years and 214 days
下面是参考答案代码:
import java.util.*;
public class YearsAndDaysQuestion7 {
public static void main(String[] args) {
int Minutes,Years,Days;
System.out.print("Enter the number of minutes : ");
Scanner MinInput = new Scanner(System.in);
Minutes = MinInput.nextInt();
Days = Minutes / 60 / 24 % 365;
Years = Minutes / 60 / 24 / 365;
System.out.println(Minutes + " minutes is approximately "
+ Years + " years and " + Days + " minutes");
MinInput.close();
}
}
运行效果:
注:编写程序要养成良好习惯
如:1.文件名要用英文,具体一点
2.注释要英文
3.变量命名要具体,不要抽象(如:a,b,c等等),形式要驼峰化
4.整体书写风格要统一(不要这里是驼峰,那里是下划线,这里的逻辑段落空三行,那里相同的逻辑段落空5行等等)
最后
以上就是腼腆钥匙为你收集整理的第二章第七题(求出年数)(Find the number of years)的全部内容,希望文章能够帮你解决第二章第七题(求出年数)(Find the number of years)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复