返回列表 發帖

109面積與體積計算

隨機產生一1-100的整數為半徑.....
May

  1. public class TQC109 {
  2.         public static void main(String arg[]) {
  3.                 int r = (int) (Math.random() * 100) + 1;

  4.                 System.out.printf("隨機產生的半徑為:%d\n\n", r);
  5.                 System.out.printf("計算後,直徑為:%d\n\n", r * 2);

  6.                 System.out.printf("計算後,圓面積為:%f\n", r * r * Math.PI);
  7.                 System.out.printf("四捨五入至小數第1位,則圓面積為:%.1f\n\n", r * r * Math.PI);

  8.                 System.out.printf("計算後,圓體積為:%f\n", r * r * Math.PI * 4 / 3);
  9.                 System.out.printf("四捨五入至小數第1位,則圓體積為:%.1f", r * r * Math.PI * 4 / 3);

  10.         }
  11. }
複製代碼
小雲雀

TOP

  1. public class jva109{
  2.         public static void main(String arg[])
  3.         {
  4.         int r=(int)(Math.random()*100)+1;
  5.        
  6.         System.out.printf("隨機產生的半徑為:%d\n\n",r);
  7.         System.out.printf("計算後,直徑為:%d\n\n",r*2);
  8.        
  9.         System.out.printf("計算後,圓面積為:%f\n",r*r*Math.PI);
  10.         System.out.printf("四捨五入至小數第1位,則圓面積為:%.1f\n\n",r*r*Math.PI);
  11.        
  12.         System.out.printf("計算後,圓體積為:%f\n",r*r*Math.PI*4/3);
  13.         System.out.printf("四捨五入至小數第1位,則圓體積為:%.1f",r*r*Math.PI*4/3);
  14.        
  15.        
  16.        
  17.        
  18.        
  19.         }
  20. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊
水桶小鄭,鯰魚

TOP

附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊
陳彥綸

TOP

返回列表