0

Loan calculator

Hi, I wrote my code to the loan calculator problem below. But the result showed “error identifier expected”. I’ve stuck for days and could not find where the the issues were. Can anyone help? import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for (i=1;i<3;i++){ int pymt = amount*0.1; int amount = amount - pymt; i++; } } System.out.println(amount); }

25th Dec 2021, 1:46 AM
Lisa
2 Respostas
+ 1
1. You have i++ in for loop and additionally in the body of the for loop. 2.Declare the variables pymt and amount before the loop, you declare them EVERY cycle in the for loop 3. You should declare variable i in for loop
25th Dec 2021, 1:54 AM
Alexey Kopyshev
Alexey Kopyshev - avatar
- 1
Just a tip for your for loop: you can initialize your variables bewtween your parentheses For example : for (int i; [condition]; [Treatment])
4th Jul 2022, 7:02 PM
Kaize Yumechi
Kaize Yumechi - avatar