代码秃头
2021-09-10 17:13
采纳率: 100%
浏览 23
已结题

JAVA中三角函数的计算错误

package s;

import java.util.Scanner;

public class sin {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    int X,K;
    String print = "" ;
    double Y = 0;
    String i = null;//switch的表达式
    Scanner sc = new Scanner(System.in);
    System.out.print("请输入X的值:");
    X = sc.nextInt();
    System.out.print("请输入K的值:");
    K = sc.nextInt();
    System.out.print("请输入三角函数:");
    i = sc.next();
    switch(i)
    {
    case "sin":  
        if(X>0 && X<=30) {
            Y =(Math.sin(X));
            print = "算式一值:"+Y;
        }
        break;
        
    case "cos":  
        if(X>30 && X<=60) {
            Y = (Math.cos((Math.pow(X, K))));
            print = "算式二值:"+Y; 
        }
        break;
    case "tan":  
        if(X>60) {
            Y = (Math.tan(X/K));
            print = "算式三值:"+Y; 
        }
        break;
    default:
        print = "输入不符合要求!"; 
        break;
    }
    System.out.print(print);
}

}

2条回答 默认 最新

相关推荐 更多相似问题