if单分支结构
if(布尔表达式){
语句块
}
- 如果if语句不写{},则只能作用于后面的第一条语句。
强烈建议,任何时候都写上{},即使里面只有一句话! ```java //掷色子游戏,最大整数6; //math.random()方法生成的数,小数位第一位最大为9 //多分支条件判断 public class DiceGame { public static void main(String[] args) {
int i=(int)(Math.random()*6+1);
int j=(int)(Math.random()*6+1);
int k=(int)(Math.random()*6+1);
int count=i+k+j;
if(count<10){
System.out.println("哦,我的运气不太行啊");
}else if(count>=10&&count<=15){
System.out.println("希望好运");
}else{
System.out.println("我一定会赢");
}
System.out.println(count);
} }
```