gpt4 book ai didi

java - 我在bluej中编译了一个switchcase程序来计算圆的一些参数。但我在编译过程中遇到了错误

转载 作者:行者123 更新时间:2023-12-01 11:00:57 24 4
gpt4 key购买 nike

错误显示-“孤立案例”。但我已经尝试了很多次并检查了牙套。程序如下-

/**
* Switch case program to calculate area, circumference, chord & area of segment of a circle
* with user interaction. User will be prompt to enter the radius and central angle of the circle.
* The result will be calcuated based on the provided radius value and central angle value.
*/
import static java.lang.Math.*;
public class CircleDemo
{
public static void main(double ch, double x, double r)
{
/**
* Here, x is the central angle of the circle and r is the radius of the circle
*/
System.out.println("1. Area of the circle"+"/n"+"2. Length of the arc of the circle"+"/n"+"3. Length of the chord of the circle"+"/n"+"4. Area of the segment of the circle"+"/n"+"Enter your choice");
Switch (ch); {
case 1:double area= PI*pow(r,2);
System.out.println("Area of the circle="+area);
break;
case 2:double arc= PI*r*(x/180);
System.out.println("Length of the arc of the circle="+arc);
break;
case 3:double chord= 2*r*sin(x/2);
System.out.println("Length of the chord of the circle="+chord);
break;
case 4:double segment= (((PI*pow(r,2)*x)/360)-((pow(r,2)*sin(x))/2));
System.out.println("Area of the segment of the circle="+segment);
break;
default:System.out.println("Invalid choice");
}
}
}

最佳答案

  1. 您无法打开 double 变量,因此请将 ch 更改为 int 或在 中将其强制转换为 int switch 语句。
  2. 开关应为开关
  3. 删除此处的; - switch (ch);

关于java - 我在bluej中编译了一个switchcase程序来计算圆的一些参数。但我在编译过程中遇到了错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33329307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com