头歌(educoder)第 2 章 Java入门之控制结构 Java入门 - 分支结构

目录

第1关:Java分支结构之 if...else

第2关:if语句测试题​编辑

 第3关:Java分支结构之多重if

第4关:Java分支结构之Switch

第5关:Switch语句测试题​编辑

第6关:来吧,我是BOSS!

 


第1关:Java分支结构之 if...else

package step2;

import java.util.Scanner;

public class HelloIfStep2 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		/******start******/
		System.out.println("请输入学员成绩:");
		int score=input.nextInt();
		if((score>=85)&&(score<=100)){
			System.out.println("优,非常棒!");
		}
		else if((score>=0)&&(score<85)){
		System.out.println("良,下次加油!");}
		
		
		
		
		/******end******/
	}
}

第2关:if语句测试题

 

 

 第3关:Java分支结构之多重if

package step3;

import java.util.Scanner;

public class HelloStep3 {
	public static void main(String[] args) {
		System.out.println("星级成绩评定系统");
		System.out.println("请输入成绩:");
		Scanner sc = new Scanner(System.in);
		/******start******/
		int score=sc.nextInt();
		if((score>=90)&&(score<=100)){
			System.out.println("*****五星成绩");
		}
		else if((score>=80)&&(score<90)){
			System.out.println("****四星成绩");
		}
		else if((score>=70)&&(score<80)){
			System.out.println("***三星成绩");
		}
		else if((score>=60)&&(score<70)){
			System.out.println("**俩星成绩");
		}
		else if((score>=0)&&(score<60)){
			System.out.println("无星成绩");
		}

		
		
		
		
		
		
		/******end******/
	}
}

第4关:Java分支结构之Switch

package step4;

import java.util.Scanner;

public class HelloSwitch {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("请输入月份:");
		
		int input = sc.nextInt();	//获取输入的月份
		
        //通过输入的月份来判断当前季节并输出
		/*****start*****/
		switch (input) {
			case 1:
            case 2:
            case 12:
             System.out.println(input+"月是冬天");
             break;
            case 3:
             case 4:
case 5:
System.out.println(input+"月是春天");
break;
case 6:
case 7:
case 8:
System.out.println(input+"月是夏天");
break;
case 9:
case 10:
case 11:
System.out.println(input+"月是秋天");
break;

}
	
		
		/*****end*****/
		
	}
}

第5关:Switch语句测试题

第6关:来吧,我是BOSS!

package step5;

import java.util.Scanner;

public class Practice {
    
    	final static Scanner sc = new Scanner(System.in);	//创建扫描仪

		//第一题
		public void first(){
			System.out.println("请输入人数:");
            int input = sc.nextInt();		//获取输入的数据
            
			/*****start*****/
			if(input<10){
				System.out.println("打半场");
			}else System.out.println("打全场");
			
			
			
			
			/*****end*****/
		}
		
		//第二题
		public void second(){
			System.out.println("请输入今天星期几:");
            int input = sc.nextInt();		//获取输入的数据
            
			/*****start*****/
			if(input==1){
				System.out.println("今天吃米饭");
			}else if(input==2){
				System.out.println("今天吃牛排");
			}else if(input==3){
				System.out.println("今天吃鸡排");
			}else System.out.println("今天吃红烧肉");

			

			
			/*****end*****/
		}	
		
		//第三题
		public void third(){
			System.out.println("请输入今天星期几:");
            int input = sc.nextInt();		//获取输入的数据
            
			/*****start*****/
			switch(input){
				case 1:System.out.println("今天吃米饭");break;
				case 2:System.out.println("今天吃牛排");break;
				case 3:System.out.println("今天吃鸡排");break;
				default :System.out.println("今天吃红烧肉");break;
			}

			
			
			
			/*****end*****/
		}
}

 

  • 14
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北沐xxx

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值