image.png

    if单分支结构
    image.png
    if(布尔表达式){
    语句块
    }

    1. 如果if语句不写{},则只能作用于后面的第一条语句。
    2. 强烈建议,任何时候都写上{},即使里面只有一句话! ```java //掷色子游戏,最大整数6; //math.random()方法生成的数,小数位第一位最大为9 //多分支条件判断 public class DiceGame { public static void main(String[] args) {

      1. int i=(int)(Math.random()*6+1);
      2. int j=(int)(Math.random()*6+1);
      3. int k=(int)(Math.random()*6+1);
      4. int count=i+k+j;
      5. if(count<10){
      6. System.out.println("哦,我的运气不太行啊");
      7. }else if(count>=10&&count<=15){
      8. System.out.println("希望好运");
      9. }else{
      10. System.out.println("我一定会赢");
      11. }
      12. System.out.println(count);

      } }

    ```