📄 switchtest2.java
字号:
/*
*分支语句功能测试
*/
import java.io.*;
public class SwitchTest2
{
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!");
case 3:
System.out.println("the season is Fall!");
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 + -