I'm getting a error code : java:23: error: cannot find symbol
monthlyPayment=(balance*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(numberOfYears*12))));
^
symbol: method pow(double,int)
location: class Math
1 error

it's pointing at Math.pow, but I dont understand what else to do thank you for any help.

import java.util.*;
 
   public class Loan
   {
   
   
   
      public static void main(String[] args)
      {
      Scanner input= new Scanner (System.in);
      double monthlyPayment=0;
      double principal=0;
      
      
      System.out.println("Loan Amount : ");
		double balance=input.nextDouble();
		System.out.println("Number of Years :   ");
		int numberOfYears=input.nextInt();
		System.out.println("Annual Interest Rate :   ");
		double interest=input.nextDouble();
		double monthlyInterestRate=interest/12;
		interest= monthlyInterestRate *balance;
      monthlyPayment=(balance*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(numberOfYears*12))));
		
      for (int i=1; i<=numberOfYears *12; i++)
      {
      
      //interest= monthlyInterestRate *balance;
      //monthlyPayment=(balance*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(numberOfYears*12))));
		
      
      principal = monthlyPayment - interest;
      balance= balance - principal;
      System.out.println(i + "\t\t" + interest
      	+"\t\t" + principal + "\t\t" + balance);
      	}
      	}
      	}

I have try doing it with a pow(double, double) and is the same message

Hmm... What IDE are you using? What Java version? I used Texpad using Java 6 to compile and run, it works fine... Though, the answer from the computation (table) is all wrong...

Edit: Hmm... What's wrong with JGRASP... Let me check...

I'm using jGrasp.

is it printing the MonthlyPayment as well?

Below is the output I get... By the way, you should use "System.out.print" instead of "System.out.println" when you accept the input from a user...

/*
Loan Amount:
10000
Number of Years:
5
Annual Interest Rate:
.1
1  83.33333333333    69361.11111111111   -5961.11111111111
2  83.33333333333    69361.11111111111   -128722.22222222222
3  83.33333333333    69361.11111111111   -198083.33333333333
4  83.33333333333    69361.11111111111   -267444.44444444444
...
...
*/

I'm guessing you have a class named "Math" in the same directory, and it is using that instead of java.lang.Math.

What I'm trying to do now is to make the answers two decimal places. it seems it not working any suggestions thank you

import java.util.*; 

import java.text.*;

public class Loan 

{ 






public static void main(String[] args) 

{ 
Scanner input= new Scanner (System.in); 

double monthlyPayment=0; 

double principal=0; 







System.out.print("Loan Amount : "); 

double balance=input.nextDouble(); 



System.out.print("Number of Years : "); 

double numberOfYears=input.nextInt(); 

System.out.print("Annual Interest Rate : "); 

double interest=input.nextDouble(); 



double monthlyInterestRate=interest/12; 



monthlyPayment=(balance*(interest/12))/(1-(Math.pow(1/(1+(interest/12)),(numberOfYears*12)))); 

System.out.println("Monthly Payment: "+monthlyPayment); 


for (int i=1; i<=numberOfYears *12; i++) 

{ 






interest= monthlyInterestRate *balance; 

principal = monthlyPayment - interest; 

balance= balance - principal; 

DecimalFormat df = new DecimalFormat("#.00"); 

System.out.println(df.format(i + "\t\t" + interest 

+"\t\t" + principal + "\t\t" + balance)); 



} 

} 

}

Line 70, try changing it to...

DecimalFormat df = new DecimalFormat("#.##");

Then line 72, you are supposed to pass in a double/float without any string.

System.out.println(i+"\t\t"+df.format(interest));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.