The %
symbol is used in a printf string for 'put a variable here'.
That's problematic when you write 4.9% interest rate
because java thinks that % i
is you saying: "a variable goes here". The fix is trivial; a double % is how you write a single percent. Thus:
System.out.printf("Your balance after one year with a 4.9%% interest rate is $%7.2f %n", balance);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…