A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

//用if语句来完成月份对应季节方法一:
                if (month > 12 || month < 1) {
                        System.out.println("对不起没有对应的季节");
                }else if (month >= 3 && month <= 5) {
                        System.out.println(month + "月是春季");
                }else if (month >= 6 && month <= 8) {
                        System.out.println(month + "月是夏季");
                }else if (month >= 9 && month <= 11) {
                        System.out.println(month + "月是秋季");
                }else {
                        System.out.println(month + "月是冬季");
                }
   
//用if语句来完成月份对应季节的方法二:
/*
                if(month>12 || month<1) {
                        System.out.println("输入的数字不正确");
                } else if (month==3 || month==4 || month==4) {
                        System.out.println("春季");
                } else if (month==6 || month==7 || month==8) {
                        System.out.println("夏季");
                } else if (month==9 || month==10|| month==11) {
                        System.out.println("秋季");
                } else {
                        System.out.println("冬季");
                }        */
        }
}

12 个回复

正序浏览
我也刚学习不久,也楼主共勉。
回复 使用道具 举报
楼主刚刚学基础吗?
回复 使用道具 举报
赞一个!!
回复 使用道具 举报
学习了,以后也要发笔记,记录自己的学习过程
回复 使用道具 举报
学习了。。。。。。。。。
回复 使用道具 举报
干的漂亮。。
回复 使用道具 举报
谢谢分享
回复 使用道具 举报
bowenfei 来自手机 中级黑马 2015-9-9 08:12:14
地板
第一种方法如果输入6.5是不是系统自动取整数部分的6?
回复 使用道具 举报
厉害厉害,赞赞赞。
回复 使用道具 举报
好好好,干得不错
回复 使用道具 举报
还有一种
import java.util.Scanner;
class A8 {
        public static void main(String[] args) {
                /*345为春季 678 位夏季 9 10 11 为秋季 12 1 2 为冬季*/
                Scanner sc = new Scanner (System.in);
                System.out.println("请输入月份");
                int month = sc.nextInt();
                switch (month){
                        case 3 :
                        case 4 :
                        case 5 :
                                System.out.println(month+"月为春季");
                                break;
                        case 6 :
                        case 7 :
                        case 8 :
                                System.out.println(month+"月为夏季");
                                break;
                        case 9 :
                        case 10 :
                        case 11 :
                                System.out.println(month+"月为秋季");
                                break;
                        case 12 :
                        case 1 :
                        case 2 :
                                System.out.println(month+"月为冬季");
                                break;
                        default:
                                System.out.println("你输入的月份有误");
                                break;

                }
        }
}
回复 使用道具 举报
王乙帆 来自手机 中级黑马 2015-9-9 00:02:37
沙发
666666666666666
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马