答案家

 找回密码
 立即注册
查看: 863|回复: 0

Java语言程序设计基础篇_第十版_梁勇_第四章17题答案!

[复制链接]

1万

主题

1万

帖子

80万

积分

校长

Rank: 9Rank: 9Rank: 9

积分
809492
发表于 2016-12-24 15:50:55 | 显示全部楼层 |阅读模式
一个月中的日期
package nameyu;
import java.util.Scanner;public class Test {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.print("Enter a year:");
        int year=input.nextInt();
        Scanner iput=new Scanner(System.in);
        System.out.print("Enter a month:");
        String month=iput.nextLine();
        char ch1=month.charAt(0);
        char ch2=month.charAt(1);
        char ch3=month.charAt(2);
        if(ch1=='J'&&ch2=='a'&&ch3=='n'){
            System.out.println("Jan "+year+" has 31 days");
        }
        else if(ch1=='F'&&ch2=='e'&&ch3=='b'){
            if((year%4==0&&year%100!=0)||(year%400==0)){
                System.out.println("Feb "+year+" has 29 days");
            }else
                System.out.println("Feb "+year+" has 28 days");
        }
        else if(ch1=='M'&&ch2=='a'&&ch3=='r'){
            System.out.println("Mar "+year+" has 31 days");
        }
        else if(ch1=='A'&&ch2=='p'&&ch3=='r'){
            System.out.println("Apr "+year+" has 30 days");
        }
        else if(ch1=='M'&&ch2=='a'&&ch3=='y'){
            System.out.println("May "+year+" has 31 days");
        }
        else if(ch1=='J'&&ch2=='u'&&ch3=='n'){
            System.out.println("Jun "+year+" has 30 days");
        }
        else if(ch1=='J'&&ch2=='u'&&ch3=='l'){
            System.out.println("Jul "+year+" has 31 days");
        }
        else if(ch1=='A'&&ch2=='u'&&ch3=='g'){
            System.out.println("Aug "+year+" has 31 days");
        }
        else if(ch1=='S'&&ch2=='e'&&ch3=='p'){
            System.out.println("Sep "+year+" has 30 days");
        }
        else if(ch1=='O'&&ch2=='c'&&ch3=='t'){
            System.out.println("Oct "+year+" has 31 days");
        }
        else if(ch1=='N'&&ch2=='o'&&ch3=='v'){
            System.out.println("Nov "+year+" has 30 days");
        }
        else if(ch1=='D'&&ch2=='e'&&ch3=='c'){
            System.out.println("Dec "+year+" has 31 days");
        }
    }
    }  

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

CopyRight(c)2016 www.daanjia.com All Rights Reserved. 本站部份资源由网友发布上传提供,如果侵犯了您的版权,请来信告知,我们将在5个工作日内处理。
快速回复 返回顶部 返回列表