}
}
double s =(edge1 + edge2 + edge3) / 2;
double area = Math.pow(s * (s - edge1) * (s - edge2) * (s - edge3), 0.5);
System.out.println(\area of the tringle is \ + String.format(\,
area));
2.20(财务应用程序:计算利息)
import java.util.*;
public class test { }
}
double interst = balance * ( annual / 1200);
System.out.println(\interst is \ + String.format(\, interst)); public static void main(String[] args) {
// TODO Auto-generated method stub Scanner input = new Scanner(System.in);
System.out.print(\); double balance = input.nextDouble(); double annual = input.nextDouble();
2.21(财务应用:计算未来投资值)
import java.util.*;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub Scanner input = new Scanner(System.in); System.out.print(\); double investment = input.nextDouble();
System.out.print(\); double interest = input.nextDouble();
11
}
}
interest = interest / 100 / 12;
System.out.print(\); double years = input.nextDouble();
double value = investment * Math.pow((1 + interest), (years * 12));
System.out.println(\ + String.format(\,
value));
2.22(财务应用:货币单位)
import java.util.*;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub Scanner input = new Scanner(System.in);
System.out.print(\); int amount = input.nextInt();
int remainingAmount = amount;
int numberOfOneDollars = remainingAmount / 100; remainingAmount = remainingAmount % 100;
int numbersOfQuarters = remainingAmount / 25; remainingAmount = remainingAmount % 25;
int numberOfDimes = remainingAmount / 10; remainingAmount = remainingAmount % 10;
int numberOfNickels = remainingAmount / 5; remainingAmount = remainingAmount % 5;
int numberOfPennies = remainingAmount;
System.out.println(\ + amount + \); System.out.println(\ + numberOfOneDollars + \); System.out.println(\ + numbersOfQuarters + \);
12
}
}
System.out.println(\ + numberOfDimes + \); System.out.println(\ + numberOfNickels + \); System.out.println(\ + numberOfPennies + \);
2.23(驾驶费用)
import java.util.*;
public class test { }
public static void main(String[] args) { }
// TODO Auto-generated method stub Scanner input = new Scanner(System.in);
System.out.print(\); double drivingDistance = input.nextDouble();
System.out.print(\); double milesPerGallon = input.nextDouble();
System.out.print(\); double pricePerGallon = input.nextDouble();
double costOfDriving = drivingDistance / milesPerGallon *
System.out.print(\ + String.format(\,
pricePerGallon; costOfDriving));
13