Jump to content
  • Advertisement
Sign in to follow this  
Xiachunyi

[java] Console Display and Tab Alignment [solved]

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am just finishing up my Amortization Table when I noticed that since I had to integrate tabbing in my application, my "thrown-together" table will ocassionally go out of alignment due to text exceeding a tab's pre-determined length. Ex. I have System.out.print(Somvar + "\t\t" + Somvar2 + "\t\t" + Somevar3);
100		150		300
100000000000		150		300
If the first or second happen to exceed the tab's length, then all the following are pushed forward and the table alignment is messed up. Is there a way to conteract this in java? I was thinking about converting the variables to strings, counting the characters, and having an if statement that will adjust the number of tabs in relation to how many characters. Thank you. [Edited by - Xiachunyi on September 5, 2005 11:38:13 PM]

Share this post


Link to post
Share on other sites
Advertisement
Thank you for the reply. I asked my professor about the problem as well and he said that my proposed method would work and the "creativity" portion of my grade would be satisfied because of it.


/*==============================================================================
Designation: String in Table Formatting
Use: Returns a string that complies with the given value length vs. table format
==============================================================================*/

public static String DispString(String Characters, int MaxLength)
{
String sCorrectedString; //Return String Container

if(Characters.length() > MaxLength)
{
sCorrectedString = Characters + "\t";
}
else
{
sCorrectedString = Characters + "\t\t";
}

return sCorrectedString;
}
}



Works for me!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use printf, you can then limit the digits printed.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!