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); }
2 odpowiedzi
+ 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
- 1
Just a tip for your for loop: you can initialize your variables bewtween your parentheses
For example : for (int i; [condition]; [Treatment])