switchtest2.java
来自「JSF 演示代码」· Java 代码 · 共 43 行
JAVA
43 行
/*
*分支语句功能测试
*/
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 + =
减小字号Ctrl + -
显示快捷键?