选择结构(if-else/swtich)
if单选择结构
if(布尔表达式){
语句块
}package com.itcode.demo1;
/**
* @author: 成都码到功成学员
* @Description:
* 抛骰子游戏
*/
public class TestIf {
public static void main(String[] args) {
System.out.println(Math.random());// 产生一个范围在(0,1)之间的double
System.out.println((int)(Math.random()*6 + 1));// 产生一个范围在(0,6)
int a = (int) (Math.random()*6+1);
int b = (int) (Math.random()*6+1);
int c = (int) (Math.random()*6+1);
int d = a + b + c;
System.out.println(d);
if(d <= 5) {
System.out.println("手气差");
}
if(d>5 && d<11) {
System.out.println("手气一般");
}
if(d >= 11) {
System.out.println("手气还可以");
}
}
}if-else双选

if-else if-else多选
switch多选

Last updated