该区域不断出现为零。我究竟做错了什么?

The area keeps coming out to zero. What am i doing wrong?

正在尝试确定三角形的面积。提示用户输入 3 个数字(双数)并计算程序内三角形的面积。该区域必须是至少 3 位小数的数字。然而,该区域一直为 0。我做错了什么?

        public static void main (String [] args) {
        double sideA = 0.0;
        double sideB = 0.0;
        double sideC = 0.0;
        int s = 1/2;
        double area = 0.000;

        Scanner scnr = new Scanner(System.in);

        System.out.println("Enter Side A: ");
        sideA = scnr.nextInt();

        System.out.println("Enter Side B: ");
        sideB = scnr.nextInt();

        System.out.println("Enter Side C: ");
        sideC = scnr.nextInt();

        DecimalFormat fmt = new DecimalFormat("0.###");

        area = Math.sqrt((s * (s - sideA) * (s - sideB) * (s - sideC)));

        System.out.println("The area of the triangle is: " + fmt.format(area));

        return;

这可能会有所帮助,我已经获取了您的代码并对其进行了处理,这就是我的代码:

 public static void main (String [] args) {
    double base;
    double height;
    double s = 2;
    double area;

    Scanner scnr = new Scanner(System.in);

    System.out.print("Enter length for the Base: ");
    base = scnr.nextInt();

    System.out.println("Enter Height of the triangle: ");
    height = scnr.nextInt();

    DecimalFormat fmt = new DecimalFormat("0.###");

    area = (height*base) / s;

    System.out.println("The area of the triangle is: " + fmt.format(area));   
 }

这将打印输出 157.5 作为您所在的地区。您已经接近它了,但是您将周长公式和面积公式结合在一起,这就是它不起作用的原因。