java - Print formation -


i asked question , got great :d my first question. thought out of woods guess not. setting up/formation information program getting running problem when trying print variable "time" if 1 point out doing wrong obliged.

the section of code believe problem is:

// class prints loan statement showing amount borrowed     // , amount borrowed, annual interest rate, number of months     // , monthly payment     public static void loanstatement(double principle, double interest, int time, double mpayment)     {        system.out.printf("%2s%13s%8s%20s%n", "principle", "interest", "time", "monthly payment");        system.out.printf("%2.2f%10.2f%10.2f%n", +principle, +interest +time);        system.out.println("monthly payment is" +mpayment);        system.out.println("interest is" +interest);        system.out.println("time is" +time); 

when take out +time , remove 10.2f (i tried many different combinations) no errors. had time , monthly payment variables being printed , got weird mesh of numbers.

i put in other printlns because wanted check program returning proper values , is.

below formatting errors getting

principle     interest    time     monthly payment exception in thread "main" java.util.missingformatargumentexception: format specifier '10.2f' 15000.00     36.07  @ java.util.formatter.format(formatter.java:2487)     @ java.io.printstream.format(printstream.java:970)     @ java.io.printstream.printf(printstream.java:871)     @ loanpayment.loanpayment.loanstatement(loanpayment.java:89)     @ loanpayment.loanpayment.main(loanpayment.java:55) java result: 1 build successful (total time: 6 seconds) 

i hope asking make sense guys, , in advance!

you providing 2 inputs here:

   system.out.printf("%2.2f%10.2f%10.2f%n", +principle, +interest +time); 

whereas requires three. maybe missing put comma(,) before +time try if logical you:

   system.out.printf("%2.2f%10.2f%10.2f%n", +principle, +interest, +time); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -