public class DubleFloatDemoRun {

public static void main(String[] args) {
     //Math is double type
      double d1;
     d1 = Math.random();
     System.out.println(d1);
     float f1 ;
     f1 = (float)Math.random();
     System.out.println(f1);

    double d2;
    d2 = (Math.random()*(90-65+1))+65; //95~65
     System.out.println(d2);
/*==============================================
X~Y的範圍 ( X 為亂數範圍的起始值,而 Y 為亂數值範圍的終止值)

(Math.random() * (Y-X+1)) + X;
=========================================*/
     double d3;
     d3 = (int)(Math.random()*(90-65+1))+65;
     System.out.println(d3);

     double d4;
     char c1; //A~Z
     d4 = (int)(Math.random()*(90-65+1))+65; //等號右邊已轉為int 但放入d4還是為double type

     int z = (int) d4;
     c1 = (char)z;
     System.out.println(c1);

     double d5;
     d5 = Math.random();
     System.out.println(Math.ceil(d5));

//Math.ceil取整數
}

}

arrow
arrow
    全站熱搜

    wealthy 發表在 痞客邦 留言(0) 人氣()