我的程序接受我输入的任何数字,甚至是 100 万 >.< 但我只想要求用户输入 0 到 180 度之间的角度,并输出该角度的正弦、余弦和正切
这是我的程序:
import java.util.Scanner;
import java.text.DecimalFormat;
public class Mathematics
{
public static void main(String args[])
{
System.out.println("Enter an Angle ");
Scanner data = new Scanner(System.in);
int x;
x=data.nextInt();
double sinx = Math.sin( Math.toRadians(x) );
double cosx = Math.cos( Math.toRadians(x) );
double tanx = Math.tan( Math.toRadians(x) );
DecimalFormat format = new DecimalFormat("0.##");
System.out.println("Sine of a circle is " + format.format(sinx));
System.out.println("cosine of a circle is " + format.format(cosx));
System.out.println("tangent of a circle is " + format.format(tanx));
}
}