- /**
- 方法 choose 让用户选择形状
- */
- public static void choose(int c){
- Scanner sc2 = new Scanner(System.in);
-
- switch (c){
- case 1 :
- System.out.println( "请输入长和宽 : ");
- System.out.println("长为:");
- double l = sc2.nextDouble();
- System.out.println("宽为:");
- double w = sc2.nextDouble();
- reArea(l,w);
- break;
- case 2 :
- System.out.println( "请输入半径 : ");
- System.out.println("半径为:");
- double radius = sc2.nextDouble();
- roArea(radius);
- break;
- case 3 :
- System.out.println("请输入底和高 :");
- System.out.println("底为:");
- double b = sc2.nextDouble();
- System.out.println("高为:");
- double h = sc2.nextDouble();
- trArea(b,h);
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- return ;
- }
- /*
- rectangle 长方形面积area 计算方法:
- 长 long 宽 width,area = long*width
- */
- public static double reArea(double l , double w){
- Scanner sc2 = new Scanner(System.in);
- double area = l*w ;
- System.out.println("长方形面积为:"+area);
- return area;
- }
- /**
- 创建方法 round 圆形计算面积area方法,
- 半径 radius,π 3.14,area = radius*radius*π
- */
- public static double roArea(double radius){
- double area = radius*radius*3.14;
- System.out.println("圆形面积为:"+area);
- return area;
- }
- /**
- 方法 triangle 三角形面积area计算方法,
- 低 bottom 高 high ,area = 1.0/2*bottom*high
- */
- public static double trArea(double b,double h){
- double area = b*h*1.0/2;
- System.out.println("三角形的面积为:"+area);
- return area;
- }
- }
复制代码 |