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("结束"); } }
时间: 2024-11-07 20:28:31