1. 程式人生 > >控制語句if單選擇結構

控制語句if單選擇結構

2018-11-09

public class TestIf {

public static void main(String[]args) {
     double d=Math.random();//返回0-1之間的隨機數每次都不同
     System.out.println(d);
     
    int h= (int) (6*Math.random()+1);//不加1 是1-5 加1是1-6之間的數字
    System.out.println(h);
    if(h<3) {
        System.out.println("小");
    }else {
        System.out.println(
"大"); } System.out.println("###############################"); int a=(int) (6*Math.random()+1); System.out.println("a數字是"+a); int b=(int)(6*Math.random()+1); System.out.println("b數字是"+b); int c=(int)(6*Math.random()+1); System.out.println(
"c的數字是"+c); int count=a+b+c; System.out.println("搖到了"+count); if(count>15) { System.out.println("今天運氣不錯搖到了大於15\t"+count); } if(count<10) { System.out.println("今天運氣不錯搖到了小於10\t"+count); } if(count>=9&&count<=15) { System.out.println(
"今天運氣不錯搖到了\t"+count); } }