A Simple Car Loan Payment Calculator


#1

I cant find out what to seem to be the problem. It should be with if?
I get the error below:

CarLoan.java:12: error: ‘else’ without ‘if’
} else if (downPayment >= carLoan) {
^
1 error

Can I please get some help?


public class CarLoan {
	public static void main(String[] args) {

	int carLoan = 10000;
  int loanLength = 3;
  int interestRate = 5;
  int downPayment = 2000;
    
    if (loanLength <= 0); {
      System.out.println("Error! You must take out a valid car loan.");

		} else if (downPayment >= carLoan) {

			System.out.println("The car can be paid in full.");

		}	else {
    	
    int remainingBalance = carLoan - downPayment;
    int months = loanLength * 12;
    int monthlyBalance = remainingBalance / months;
    int interest = monthlyBalance * interestRate / 100;
    int monthlyPayment = monthlyBalance + interest; 

    System.out.println(monthlyPayment);
  
  	}
	}
}

#2

Hey @sabinagoransson,

I am not familiar with java, but I think that there must be no semicolon here:

if (loanLength <= 0);

Again, I don’t really know anything about Java, but I hope this helps.


#3

Sounds about right, the semi-colon interrupts the if clause, which will then else if clause to throw an error.


#4

Thank you! I totally missed it :slight_smile:


#5

Thank you! I totally missed it :slight_smile: That was correct, thank you for your help!


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.