解题思路:
注意事项:所谓的宏定义就是定义一个函数
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double a = scanner.nextDouble(); double b = scanner.nextDouble(); double c = scanner.nextDouble(); double area = getArea(a, b, c); System.out.printf("%.3f",area);//保留3位小数 } //求面积area //需要参数a,b,c //需要返回最后的结果,类型为double,所以void换成double public static double getArea(double a,double b,double c) { double s = getS(a, b, c); double area = Math.sqrt(s*(s - a)*(s - b)*(s - c)); return area; } //求S //需要a,b,c //需要返回值 public static double getS(double a,double b,double c) { double S = (a + b + c)/2; return S; } }
0.0分
1 人评分