第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我怎樣才能正確舍入這個數(shù)字?

我怎樣才能正確舍入這個數(shù)字?

繁星coding 2023-09-27 21:18:37
我應(yīng)該得到 PI 和 PI/2 的余弦和正弦以及角度 0。除了 PI/2 的余弦之外,我的所有數(shù)字都是正確的。預(yù)期輸出:Radians: (cos, sin)0.0: 1.0, 0.01.5707963267948966: 0.0, 1.03.141592653589793: -1.0, 0.0我的輸出:Radians: (cos, sin)0.0: 1.0, 0.01.5707963267948966: 1.0, 1.03.141592653589793: -1.0, 0.0public class UnitCircle {    public static void main(String[] args)    {        System.out.println("Radians: (cos, sin)");        double angle = 0.0;        double piDivideTwo = Math.PI/2.0;        double pi = Math.PI;        System.out.println(angle + ": " + Math.cos(angle) + ", " + Math.sin(angle) );        double cosine = Math.cos(piDivideTwo);         cosine = Math.round(cosine * 100) / 100.0;        System.out.println(piDivideTwo + ": " + Math.cos(cosine) + ", " + Math.sin(piDivideTwo) );        double sin = Math.sin(pi);        sin = Math.round(sin *100) / 100.0;        System.out.println(pi + ": " + Math.cos(pi) + ", " + Math.sin(sin) );    }}
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經(jīng)驗 獲得超8個贊

為什么它似乎可以使用兩次,cos或者sin只是因為它的價值0


您只需要計算一次cos,sin,然后按格式打印,因為 PI/2 和 PI 不可能是完美值


static void cosSin(double angle) {

    double cos = Math.cos(angle);

    double sin = Math.sin(angle);

    System.out.printf("%.4f : %.1f %.1f \n", angle, cos, sin);

}


public static void main(String[] args) {

    System.out.println("Radians: (cos, sin)");

    double angle = 0.0;

    double piDivideTwo = Math.PI / 2.0;

    double pi = Math.PI;

    cosSin(angle);        // 0,0000 :  1,0 0,0

    cosSin(piDivideTwo);  // 1,5708 :  0,0 1,0

    cosSin(pi);           // 3,1416 : -1,0 0,0

}


查看完整回答
反對 回復(fù) 2023-09-27
  • 1 回答
  • 0 關(guān)注
  • 96 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號