- 488 名前:デフォルトの名無しさん mailto:sage [2009/10/28(水) 20:19:12 ]
- class A
{ public static void main(String args[]) { int height = 160; int weight = 47; double rohrer1 = 10000000*weight/(height*height*height); double rohrer2 = weight/(height*height*height)*10000000; System.out.println("ローレル指数:" + rohrer1); System.out.println("ローレル指数:" + rohrer2); } } //結果 114.0 0.0 このコードを double rohrer1 = 10000000*(double)weight/(height*height*height); double rohrer2 = (double)weight/(height*height*height)*10000000; こう変えると結果が 114.74- 114.74-になるのはなぜですか? 小数点以下も表示したいので、キャスト演算子を使っただけなのですが、、、
|

|