Java在线等,挺急的 10
1个回答
展开全部
package demo;
import java.util.Scanner;
public class Student {
String test(double a,double b){
double temp=a*b;
String s="长为"+a+",宽为"+b+"的长方形面积为"+temp;
return s;
}
String test(double a,double b,double c){
double temp=((1.0/4.0)*Math.sqrt((a+b+c)*(a+b-c)*(a+c-b)*(b+c-a)));
String s="三边为"+a+","+b+","+c+"的三角形面积"+temp;
return s;
}
String test(double a){
double temp=a*a;
String s="边长为"+a+"的正方形面积"+temp;
return s;
}
void manage(){
Student s=new Student();
Scanner input=new Scanner(System.in);
try {
System.out.println("请选择要计算的图形:1:长方形,2三角形,3正方形,4退出");
int choose=input.nextInt();
switch (choose) {
case 1:
System.out.println("请输入长");
double a=input.nextDouble();
System.out.println("请输入高");
double b=input.nextDouble();
System.out.println(s.test(a,b));
manage();
break;
case 2:
System.out.println("请输入边长");
double x=input.nextDouble();
System.out.println("请输入边长");
double y=input.nextDouble();
System.out.println("请输入边长");
double z=input.nextDouble();
System.out.println(s.test(x,y,z));
manage();
break;
case 3:
System.out.println("请输入边长");
double m=input.nextDouble();
System.out.println(s.test(m));
manage();
break;
case 4:
break;
default:
System.out.println("错误,重新输入");
manage();
break;
}
} catch (Exception e) {
System.out.println("输入参数不正确");
manage();
}
}
public static void main(String[] args) {
Student demo=new Student();
demo.manage();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询