Java receives a ranking (int) from the keyboard and uses switch-case to make the following branch

Received from the keyboard a ranking (int) using switch-case for the following branches
ranking of 1 prize IPHONE12 pro Max
Rank 2 prize IPHONE12 pro
ranking of 3 award IPHONE12
Rank 4 prize IPHONE12 mini
other rank it up, Junior
(own beginner Java do Small exercises)

import java.util.Scanner;

public class TestDemo{
    
    
	public static void main(String[] args){
    
    
		Scanner sc=new Scanner(System.in);//与键盘连接
		System.out.println("请问你名次多少(请填整数):");
		int ranking=sc.nextInt();
		if(ranking>=1 && ranking<=4)
		switch (ranking){
    
    
			case 1:System.out.println("奖Iphone12Pro Max一部");break;
			case 2:System.out.println("奖Iphone12Pro一部");break;
			case 3:System.out.println("奖Iphone12一部");break;
			case 4:System.out.println("奖Iphone12 Mini一部");break;
			default:break;
		}else{
    
    
			System.out.println("请你再接再厉");
		}		
	}
}

The results of the operation are as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_43462140/article/details/114105832