2021-01-19 Chapter2_19error Chapter2_20

package com.company;
import java.util.Scanner;
public class Chapter2_19 {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.println("Enter three points for a triangle: ");
        double x1 = input.nextDouble();
        double x2 = input.nextDouble();
        double x3 = input.nextDouble();
        double y1 = input.nextDouble();
        double y2 = input.nextDouble();
        double y3 = input.nextDouble();
        double b1 = Math.pow((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2),0.5);
        double b2 = Math.pow((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3),0.5);
        double b3 = Math.pow((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1),0.5);
        double s = (b1 + b2 + b3) / 2;
        double area = Math.pow(s * (s - b1) * (s - b2) * (s - b3),0.5);
        System.out.println("The area of the triangle is " + area);
    }
}

/Users/wanshuai/Library/Java/JavaVirtualMachines/openjdk-15.0.1/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=49335:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/wanshuai/IdeaProjects/untitled/out/production/untitled com.company.Chapter2_19
Enter three points for a triangle: 
1.5 -3.4 4.6 5 9.5 -3.4
The area of the triangle is 13.605000000000025

Process finished with exit code 0
 

书上的答案是33.6

package com.company;
import java.util.Scanner;
public class Chapter2_20 {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.println("Enter balance and interest rate (e.g., 3 for 3%): ");
        double balance = input.nextDouble();
        double interestRate = input.nextDouble();
        double interest = (int)(balance * (interestRate  / 1200) * 100000) / 100000.0;
        System.out.println("The interest is " + interest);

    }

}

/Users/wanshuai/Library/Java/JavaVirtualMachines/openjdk-15.0.1/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=49533:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/wanshuai/IdeaProjects/untitled/out/production/untitled com.company.Chapter2_20
Enter balance and interest rate (e.g., 3 for 3%): 
1000 3.5
The interest is 2.91666

Process finished with exit code 0
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值