栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java语言程序设计 例题3.5(给出未来的日期)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java语言程序设计 例题3.5(给出未来的日期)

*3.5(Find future dates)Write a program that prompts the user to enter an integer for today's day of the week(Sunday is 0,Monday is 1,...,and Saturday is 6).Also prompt the user to enter the number of days after today for a future day and display the future day of the week.Here is a sample run:

Enter today’s day:1
Enter the number of days elapsed since today:3
Today is Monday and the future day is Thursday
Enter today’s day:0
Enter the number of days elapsed since today:31
Today is Sunday and the future day is Wednesday
*3.5(给出未来的日期)编写一个程序来提示用户输入一个数字代表今天的日期(Sunday is 0,Monday is 1,...,and Saturday is 6)并提示用户输入从今天开始经过了多少天的天数并且显示这天是星期几.这里是一个例子:

Enter today’s day:1
Enter the number of days elapsed since today:3
Today is Monday and the future day is Thursday
Enter today’s day:0
Enter the number of days elapsed since today:31
Today is Sunday and the future day is Wednesday

代码如下:

import java.util.Scanner;
public class Unite3Test5 
{
	public static void main(String[] args) 
	{
		Scanner scan=new Scanner(System.in);
		System.out.println("请输入代表今天的整数:");
		int num=scan.nextInt();
		System.out.println("请输入从今天开始经过的天数:");
		int days=scan.nextInt();
		switch(num) 
		{
			case 0:
				System.out.println("今天是周日");
				break;
			case 1:
				System.out.println("今天是周一");
				break;
			case 2:
				System.out.println("今天是周二");
				break;
			case 3:
				System.out.println("今天是周三");
				break;
			case 4:
				System.out.println("今天是周四");
				break;
			case 5:
				System.out.println("今天是周五");
				break;
			case 6:
				System.out.println("今天是周六");
				break;
		}
		int number=(days+num)%7;
		switch(number) 
		{
			case 0:
				System.out.println("经过"+days+"后是周日");
				break;
			case 1:
				System.out.println("经过"+days+"后是周一");
				break;
			case 2:
				System.out.println("经过"+days+"后是周二");
				break;
			case 3:
				System.out.println("经过"+days+"后是周三");
				break;
			case 4:
				System.out.println("经过"+days+"后是周四");
				break;
			case 5:
				System.out.println("经过"+days+"后是周五");
				break;
			case 6:
				System.out.println("经过"+days+"后是周六");
				break;
		}
		
	}
}

 结果如下:

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/880557.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号