忍者ブログ
まにょのITメモ
[30]  [29]  [28]  [27]  [26]  [25]  [24]  [23]  [22]  [21]  [20
×

[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
 

PR
この記事にコメントする
お名前
タイトル
文字色
メールアドレス
URL
コメント
パスワード   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
この記事へのトラックバック
この記事にトラックバックする:
この記事のURL:
忍者ブログ * [PR]