java - how can i make this printf print the method without formatting errors -


how can make printf output method without errors in printf code. teacher did not go on formatting simple example.

public static void printreportheadings(int [] employeeid, int [] dependents, double [] hours, double [] payrate ) {     system.out.println("                             abc payroll system ");     system.out.println(" employeeid " + " gross pay " + " federal tax " + " state tax " + " net pay ");      (int = 0; <7;i++)     {         float gross;         double federal =0.0;         double state = 0.0;         double net = 0.0;          gross = (float)(hours[i]*payrate[i]);         federal = .2 * (gross-(dependents[i]*38.46));         state = .032*gross;          net = gross - (federal+state);           system.out.printf("%-15d %.01f % 15f%n", employeeid[i], gross, federal  , state, net) ;       } 

you've got 3 placeholders , 5 things you're trying bind placeholders.

observe:

 system.out.printf("%-15d %.01f % 15f%n", employeeid[i], gross, federal, state, net); 

%-15d, %.01f, , %15f placeholders integer, 2 floating-point numerals respectively. other 2 - state , net - don't have placeholder.

adding couple more placeholders floating point type fix issue:

system.out.printf("%-15d %.01f %15f %10f %10f%n", employeeid[i], gross, federal, state, net); 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -