本文主要是介绍案例:减肥计划(if语句),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
案例:减肥计划(if语句)
//需求:输入星期数,显示今天的减肥计划
//周一:跑步,周二:游泳,周三:慢走,周四:动感单车,周五:拳击,周六:爬山,周日:好好吃一顿import java.util.Scanner;public class HelloWorld {public static void main(String[] args) {System.out.println("请输入一个星期数");Scanner sc = new Scanner(System.in);int week = sc.nextInt();if (week == 1) {System.out.println("星期一:跑步");} else if (week == 2) {System.out.println("星期二:游泳");}else if (week == 3) {System.out.println("星期三:慢走");}else if (week == 4) {System.out.println("星期四:动感单车");}else if (week == 5) {System.out.println("星期五:拳击");}else if (week == 6) {System.out.println("星期六:爬山");}else if (week == 7) {System.out.println("星期日:好好吃一顿");}else{System.out.println("您输入的星期数有误");}}
}
这篇关于案例:减肥计划(if语句)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!