本文介绍了我需要将弧度转换为度数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将弧度转换为度数,但在将其实现到我的代码中时会遇到错误。我确信有一些简单的东西我不知道但是我不知道它是什么。



我尝试了什么:



I need to convert radians to degrees but I keep getting errors when implementing it into my code. I'm sure there is something simple I am missing but I just can't get what it is.

What I have tried:

package methods;
/**
 *
 * @author stephenwessels
 */
import java.util.Scanner;
public class Methods
{
    Scanner in = new Scanner(System.in);
    public int rad2deg()
    {
        int deg;
        int rads;
        deg = in.nextInt();
        rads = in.nextInt();
        return deg;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
       Scanner in2 = new Scanner(System.in);

        System.out.println("This caluclator requires you to enter a function and a number.\n The functions are as follows:\n S - sine \n C - cosine \n T - tangent \n R - Square Root"
                + "\n N - natural log \n X 0 - Exit Program \n \n Please enter a function then a value.");

        String input = in2.nextLine().toUpperCase();

        char operation = input.charAt(0);

        String sValue = input.substring(2);

        double dNum = Double.parseDouble(sValue);


        while(!"X 0".equals(input))
            {
        switch(operation)
                {
            case 'S':
                double sine = Math.sin(dNum);
                System.out.println("The sine of your number is " + sine);
                System.out.println("The sine of your number in degrees is " + deg);
                break;
             case 'C':
                double cosine = Math.cos(dNum);
                System.out.println("The cosine of your number is " + cosine);
                System.out.println("The cosine of your number in degrees is " + deg);
                break;
             case 'T':
                double tangent = Math.tan(dNum);
                System.out.println("The tangent of your number is " + tangent);
                System.out.println("The tangent of your number in degrees is " + deg);
                break;
             case 'R':
                double Sq = Math.sqrt(dNum);
                System.out.println("The square root of your number is " + Sq);
                break;
             case 'N':
                double log = Math.log(dNum);
                System.out.println("The double log of your number is " + log);
                break;
                }
                input = in2.nextLine().toUpperCase();
            }
        System.out.println("Thanks for using the calculator.");
    }

}

推荐答案

public class JavaApplication26 {
    static int deg;  // declare it here
    Scanner in = new Scanner(System.in);
     .....

之间,函数 rad2deg 在哪里被调用?

Between, where did function rad2deg get called ?


这篇关于我需要将弧度转换为度数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 06:13