package com.Study.fishc;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
* @Description Java练习题2【控制流程】JAVA的switch &while语句--季节&阶乘
* @Classname IsSeason
* @Date 2021/8/27 19:38
* @Created by 折腾的小飞
*/
public class IsSeason {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
isSeason();
System.out.println("阶乘是:" + factorial());
}
/**
* description: 判断季节
* @since: 1.0.0
* @author: 涂鏊飞tu_aofei@163.com
* @date: 2021/8/27 20:10
* @return: void
*/
private static void isSeason() {
System.out.println("请输入月份:");
String month = scanner.nextLine();
if (month.equals(null) || month.equals("0")) {
throw new InputMismatchException("月份输入错误!");
}
switch (Integer.valueOf(month)) {
case 1:
case 2:
case 3:
System.out.println("春天");
break;
case 4:
case 5:
case 6:
System.out.println("夏天");
break;
case 7:
case 8:
case 9:
System.out.println("秋天");
break;
case 10:
case 11:
case 12:
System.out.println("冬天");
}
}
/**
* description: 求阶乘
* @since: 1.0.0
* @author: 涂鏊飞tu_aofei@163.com
* @date: 2021/8/27 20:11
* @return: double
*/
private static double factorial() {
System.out.println("请输入一个整数:");
int n = scanner.nextInt();
int sum = 1;
while (n > 1) {
sum *= n;
n--;
}
return sum;
}
}
|