Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How do you align the last line, so it is perfectly order.

java align printf

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 monkeybusiness

monkeybusiness

    CC Lurker

  • New Member
  • Pip
  • 6 posts

Posted 05 November 2015 - 07:13 PM

Java hw, almost done, i just need to align the last row it match up with the others rows and column


Here is the code 

 public String title()
  {
    return String.format("%s %70s %14s %15s %10s %10s %11s  %10s",
                         "Account", "Credit","Credit","Ending", "Account", "Penalty", "Average", "Interest");
  }
 
 public String title2()
 {
   return String.format("%s%17s %17s %20s %15s %13s %17s %9s %7s %14s %10s", 
                        "Number", "Customer ID", "Last Name", "First Name", "Score",  "Limit", "Balance", "Status", "Fee", "Balance", "Rate" );
 }

                       

public String toString()
{
  return String.format("%d      %s          %.2f        %.2f      %s        %-2.2f       %.2f       %.2f ",
                       accNum,  customer,   credLim,    endBal,   status,   penalty,   average,   interest );
}


Attached Thumbnails

  • align.PNG


#2 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 06 November 2015 - 10:48 PM

You need to specify minimum field widths, like %5.2f


sudo rm -rf / && echo $'Sanitize your inputs!'





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download