import java.util.Scanner;
public static void main(String[] args)
{
//Interest rate,number of years,loan amount; display the monthly total payments
Scanner input = new Scanner(System.in);
//Ask for interest rate
System.out.println("Enter your interest rate : ");
//Get interest rate
double interestRate = input.nextDouble();
//Ask number of years
System.out.println("Enter the number of years for this loan : ");
//Get number of years
double numberOfYears = input.nextDouble();
//Ask for loan amount
System.out.println("Enter your loan amount : ");
//Get loan amount
double loanAmount = input.nextDouble();
//Monthly interest rate
double monthlyInterestRate = interestRate / 12;
//Monthly payment
double monthlyPayment = (loanAmount * monthlyInterestRate) /
1 - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears*12)
;
//Total payment
System.out.println("total payment is : " + monthlyPayment * 12 * numberOfYears);
}
When I enter a interest rate as my first input, for example 2.5
or 2.0
it gives
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at Sal.main(Sal.java:17)
I put in double variable, it wants integer. I don't understand. And yes I did import Scanner and type my class. I bought my computer 1 week ago. Same code should work fine because it was from my exercise book.