⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 switchtest.java

📁 编程之道--java程序设计入门源代码
💻 JAVA
字号:
/*
*分支语句功能测试
*/
import java.io.*;
public class SwitchTest
{
	public static void main(String[] args)
	{
		String strIn = "";
		InputStreamReader in = new InputStreamReader(System.in);
		BufferedReader buffIn = new BufferedReader(in);
		System.out.print("Please enter a month(1-12): ");
		try
		{
			strIn = buffIn.readLine();//从命令行读入数据
		}
		catch (IOException e)
		{
	    System.out.println(e.toString());
		}
		int month = Integer.parseInt(strIn);//将字符串转变成整数型
		int season = 0;
		if (month <12 && month >0)
			season = ((month + 10) % 12)/3 + 1;//计算季节的公式
		switch(season)
		{
			case 1:
				System.out.println("the season is Spring!");
				break;
			case 2:
				System.out.println("the season is Summer!");
				break;
			case 3:
				System.out.println("the season is Fall!");
				break;
			case 4:
				System.out.println("the season is Winter!");
				break;
			default:
				System.out.println("this is not correct month!");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -