黑马程序员技术交流社区

标题: 今天学的代码,根据输入月份输出季节 [打印本页]

作者: sq_jun    时间: 2015-1-20 22:16
标题: 今天学的代码,根据输入月份输出季节
  1. /**
  2. *
  3. * @author 张耀军
  4. */
  5. import java.util.Scanner;
  6. class  abc
  7. {
  8.         public static void main(String[] args)
  9.         {
  10.             int i=1;
  11.             i*=2;
  12.                 String season[]={"春","夏","秋","冬"};
  13.               
  14.                
  15.                 String str="";
  16.                 try{
  17.                         Scanner sc=new Scanner(System.in);
  18.                 System.out.println("请输入月份:");
  19.                 int month=sc.nextInt();
  20.                
  21.                 if(month==1||month==2||month==12)
  22.                         str=season[3];
  23.                 else if(month==3||month==4||month==5)
  24.                         str=season[0];
  25.                 else if(month==6||month==7||month==8)
  26.                         str=season[1];
  27.                 else if(month==9||month==10||month==11)
  28.                         str=season[2];
  29.                 else
  30.                         str="输入有误";
  31.                 System.out.println(str);

  32. }catch(Exception e){
  33.                    e.printStackTrace();
  34.                 }
  35.               
  36.         }
  37. }

复制代码

作者: 梦开始的地方    时间: 2015-1-21 16:03
请问,你也是java刚开始学基础吗?
作者: qq306149769    时间: 2015-1-21 21:45
加油!如果在基础班,进度也挺快的,有时间尽量自己往下看视频!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2