码迷,mamicode.com
首页 > 其他好文 > 详细

输入月份显示季节 练习

时间:2014-10-29 23:36:33      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   java   sp   div   on   log   

import java.util.Scanner;   //用Scanner前先倒入此包
public class Season {
    static String sp="春天", su="夏天",au="秋天",wi="冬天";
    //静态方法 要用静态变量 要有 static
        
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("请输入月份,我判断季节");
        Scanner sc =new Scanner(System.in);
        int yue=sc.nextInt();
        if(3<=yue&&yue<=5)//if()后没有“;”号
        {
            System.out.println(sp);}
        else if(6<=yue&&yue<=8){
            System.out.println(su);}
        else if(9<=yue&&yue<=11){
            System.out.println(au);}
        else if(yue==1||yue==2||yue==12){
            System.out.println(wi);}
        else//else后没有()
        {System.out.println("请正确输入月份");
        }
            System.out.println("结束");
        }
        }
    

 

输入月份显示季节 练习

标签:style   blog   color   ar   java   sp   div   on   log   

原文地址:http://www.cnblogs.com/mimimimimi/p/4060547.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!