HW5.7

 1 import java.util.Scanner;
 2
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8
 9         System.out.print("The amount invested: ");
10         double investAmount = input.nextDouble();
11         System.out.print("Annual interest rate: ");
12         double annualInterestRate = input.nextDouble();
13
14         input.close();
15
16         System.out.printf("%s\t%s\n", "Years", "Future Value");
17
18         for(int i = 1; i <= 30; i++)
19             System.out.printf("%d\t%f\n", i, futureInvestmentValue(investAmount, annualInterestRate / 12, i));
20     }
21
22     public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)
23     { return investmentAmount * Math.pow((1 + monthlyInterestRate), (years * 12)); }
24 }
时间: 2024-10-29 19:07:28

HW5.7的相关文章

HW5.1

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 int count = 0; 6 7 for(int i = 1; i <= 100; i++) 8 { 9 System.out.print(getPentagonalNumber(i) + " "); 10 count++; 11 12 if(count == 10) 13 { 14 System.out.println();

HW5.14

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\n", "i", "m(i)"); 6 7 for(int i = 10; i <= 100; i += 10) 8 System.out.printf("%d\t%f\n", i, getMi(i * 1.0)); 9

HW5.2

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter the number: "); 9 long number = input.nextLong(); 10 11 input.close(); 12

HW5.13

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\n", "i", "m(i)"); 6 7 for(int i = 1; i <= 20; i++) 8 System.out.printf("%d\t%f\n", i, getMi(1.0 * i)); 9 } 10 1

HW5.10

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 int count = 0; 6 7 for(int i = 1; i < 10000; i++) 8 if(isPrime(i)) 9 count++; 10 11 System.out.println("The count of the prime number smaller than 10000 is: " + count)

HW5.30

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 for(int i = 3; i <= 1000; i++) 6 if(isDoublePrime(i)) 7 System.out.println("(" + i + ", " + (i + 2) + ")"); 8 } 9 10 public static boolean isDouble

HW5.4

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter a number: "); 9 int number = input.nextInt(); 10 11 input.close(); 12 13 r

HW5.32

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 int n1 = (int)(Math.random() * 5 + 1); 6 int n2 = (int)(Math.random() * 5 + 1); 7 int winCount = 0; 8 9 for(int i = 0; i < 10000; i++) 10 { 11 if(diceGame(n1, n2)) 12 winCount

HW5.9

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\t%s\t%s\n", "Inch", "Meter", "Meter", "Inch"); 6 7 for(double i = 1, j = 20; i <= 10 && j <

HW5.3

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter a number: "); 9 int number = input.nextInt(); 10 11 input.close(); 12 13 S