Is there anyway I can fix the 'possible loss of precision' error in my Java program below without changing the int value 'start' to a double?
/*4. Write a program to calculate and display the amount of money in a bank
account that was opened with a deposit of €20 fifteen years ago and has
earned interest at 10% (compound interest) per annum. Your program
should display the amount of money in the account at the end of each year
for all of the 15 years. Your program should also display the total interest
earned at the end of 15 years.*/
import java.text.DecimalFormat;import java.text.NumberFormat;public class Q4_Int_Double{ public static void main (String [] args) { int start = 20; double interest = 0.10; double totalInt; NumberFormat formatter = new DecimalFormat("0.00"); for (int counter = 1; counter <=15; counter ++) { totalInt = (start / 100) * interest; start = start + totalInt; System.out.println("Year " + counter + " Total €" + formatter.format(start)); } }}
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.