java編程基礎篇-------> 從鍵盤輸入一位整數,代表月份,編程判斷指定月份屬於一年中的哪個季度。如果是 12 月、1 月、2 月,就屬於冬季。

來源:互聯網
上載者:User

標籤:import   rgs   code   sof   log   new   div   auto   mon   

  從鍵盤輸入一位整數,代表月份,編程判斷指定月份屬於一年中的哪個季度。如果是 12月、1 月、2 月,就屬於冬季;如果是 3 月、4 月、5 月,就屬於春季;如果是 6 月、7 月、8 月,就屬於夏季;如果是 9 月、10 月、11 月,就屬於秋季。輸入其他數字時提示使用者輸入不正確。
 1 package Exam01;   2    3 import java.util.Scanner;   4    5 public class Topic05 {   6    7     public static void main(String[] args) {   8         // TODO Auto-generated method stub   9         int month = 0;  10         Scanner input = new Scanner(System.in);  11         System.out.println("請輸入月份:");  12         int mouth=input.nextInt();  13         switch(month){  14             case 12:  15             case 1:  16             case 2:  17             System.out.println(mouth+"是冬季");  18             break;  19             case 3:  20             case 4:  21             case 5:  22             System.out.println(mouth+"是春季");  23             break;  24             case 6:  25             case 7:  26             case 8:  27             System.out.println(mouth+"是夏季");  28             break;  29             case 9:  30             case 10:  31             case 11:  32             System.out.println(mouth+"是秋季");  33             break;  34         default:  35             System.out.println("輸入不正確");  36         }  37     }  38   39 }  

 

java編程基礎篇-------> 從鍵盤輸入一位整數,代表月份,編程判斷指定月份屬於一年中的哪個季度。如果是 12 月、1 月、2 月,就屬於冬季。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.