[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
★Mathクラスのメソッド
abs ・・・引数の絶対値を返す
ceil ・・・引数の値以上で最小の整数を返す
floor ・・・引数の値以下で最大の整数を返す
public class SampleMath {
public static void main(String[] args) {
double d = 100;
System.out.println("abs : " + Math.abs(d));
System.out.println("ceil : " + Math.ceil(d));
System.out.println("floor : " + Math.floor(d));
}
}
~実行結果~
abs : 100.0
ceil : 100.0
floor : 100.0
--------------------------------------------------------------------
public class SampleMath {
public static void main(String[] args) {
double d = 100.1;
System.out.println("abs : " + Math.abs(d));
System.out.println("ceil : " + Math.ceil(d));
System.out.println("floor : " + Math.floor(d));
}
}
~実行結果~
abs : 100.1
ceil : 101.0
floor : 100.0
--------------------------------------------------------------------
public class SampleMath {
public static void main(String[] args) {
double d = -100.1;
System.out.println("abs : " + Math.abs(d));
System.out.println("ceil : " + Math.ceil(d));
System.out.println("floor : " + Math.floor(d));
}
}
~実行結果~
abs : 100.1
ceil : -100.0
floor : -101.0