2020 |
07,20 |
public class MyApp {
public static void main(String[] args) {
double d = 53.234;
//Math.ceil()というメソッドを使うと小数点以下を切り上げる
System.out.println(Math.ceil(d));//54
//Math.floor()は小数点以下を切り捨てる
System.out.println(Math.floor(d));//53
//Math.PI()は円周率を取得する
System.out.println(Math.PI);
//乱数を発生させるにはMath.random()を使用する
//※使用する際はimportが必要
Random r =new Random();
//0以上1未満の浮動小数点数を取得する場合
System.out.println(r.nextDouble());//0-1
//0から100未満の整数を取得する場合
System.out.println(r.nextInt(100));//0-100
//ランダムなTrue / Falseを取得したい場合
System.out.println(r.nextBoolean());
}
}
出力結果☟
出力結果☟
:\Users\81801>java MyApp
54.0
53.0
3.141592653589793
0.9353313102109223
32
false
PR
Post your Comment