Java入门 - 分支结构

第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)
        System.out.println("良,下次加油!");
		else 
        System.out.print("优,非常棒!");
		
		
		/******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.print("*****五星成绩");
        else if(score>=80)
            System.out.print("****四星成绩");
        else if(score>=70)
            System.out.print("***三星成绩");
        else if(score>=60)
            System.out.print("**俩星成绩");
        else
            System.out.print("无星成绩");
        
		/******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 3:
            case 4:
            case 5:System.out.print(input+"月是春天");
            break;
            case 6:
            case 7:
            case 8:System.out.print(input+"月是夏天");
            break;
            case 9:
            case 10:
            case 11:System.out.print(input+"月是秋天");
            break;
            case 12:
            case 1:
            case 2:System.out.print(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*****/
		}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值