import java.util.*; //匯入util
public class fanshaped //宣告程式名稱 p.s.需與擋名相同
{
public static void main(String[] args) //基本宣告
{
Scanner sc = new Scanner(System.in); //宣告sc做為讀入使用者件盤輸入值的物件
System.out.printf("請輸入角度(0~360): "); //提示使用者輸入角度
float angle = sc.nextFloat(); //宣告變數angle儲存鍵盤輸入,資料型態為單精度浮點數
System.out.printf("請輸入半徑(大於0): "); //提示使用者輸入半徑
float radius = sc.nextFloat(); //宣告變數radius儲存鍵盤輸入,資料型態為單精度浮點數
double fanshaped, fangirth; //宣告變數fanshaped為面積,fangirth為周長,資料型態為倍精度浮點數
fanshaped = radius * radius * Math.PI * ( angle / 360 ); //面積公式 = 半徑 *
半徑 * PI * (角度 / 360) p.s. Math.PI為Java內建函式用以表PI(3.1415962...)
fangirth = radius * 2 + ( radius * 2 * Math.PI * ( angle / 360 ) ); //周長公式 = 直徑 + 直徑 * PI * (角度 / 360)
System.out.printf( "扇形面積為:%g \n",fanshaped ); //顯示面積
System.out.printf( "扇形周長為:%g \n",fangirth ); //顯示周長
}
}
- Mar 22 Tue 2011 01:53
110307物件作業--扇形面積與周長
close
全站熱搜
留言列表
發表留言