0

このプログラムをどのように終了しますか? 計算をコードに入力した場所が間違っていることはわかっています。プログラムが割り当てられたとおりに動作するようにするには、何を変更する必要がありますか (画像を参照)。また、ユーザーが最後に再計算することを選択した場合、どこをループして再計算しますか?

package cosx;

import java.util.Scanner;

public class cosx2 {

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    System.out.print("Enter the degree: ");
    double degree = input.nextDouble(); 

    double radian = getRadian(degree);

    calculateCos(input, radian,degree);

}


public static double getRadian(double x) {      
    return x = (Math.PI/180)*x;     
}

private static void calculateCos(Scanner std, double rad, double deg) {
    System.out.print("How many terms do you want to calculate the cos: ");
    int terms = std.nextInt();
    double top;
    double bottom;
    double sum=0;

    for(int i = 0; i<= terms; ++i){
        top = Math.pow(-1, i);          
        bottom =1;
        int repeat = 2*i+1;
        for(int j = 1; j <= repeat; ++j){               
            bottom *= j; 
        }
        if(i%2 == 0)
            sum += (top/bottom);
        else
            sum -= (top/bottom);
    }
    System.out.printf("The sin (%.1f", deg);
    System.out.printf(") is %.6f", sum);        
     }
    }
4

0 に答える 0