How do you output in two columns?

Thread Solved
Reply

Join Date: Oct 2007
Posts: 8
Reputation: Amurka is an unknown quantity at this point 
Solved Threads: 0
Amurka Amurka is offline Offline
Newbie Poster

How do you output in two columns?

 
0
  #1
Nov 5th, 2007
Annual Interest Rate Monthly Payment

11.00 952.32
11.25 971.26
11.50 990.29
11.75 1009.41
12.00 1028.61



I've done the hard part and completed the project, but I can't figure out how to get my program to output in two columns like above. Since this site doesn't take spacing, black column is one column and the red is the other column. Do you just wing it and add a bunch of spaces in or is there a proper way to do it?
Last edited by Amurka; Nov 5th, 2007 at 6:04 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,122
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 472
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: How do you output in two columns?

 
0
  #2
Nov 5th, 2007
The Java Tutorials - String
Using String's static format() method allows you to create a formatted string that you can reuse, as opposed to a one-time print statement. For example, instead of

  1. System.out.printf("The value of the float variable is %f, while the value of the " +
  2. "integer variable is %d, and the string is %s", floatVar, intVar, stringVar);

you can write

  1. String fs;
  2. fs = String.format("The value of the float variable is %f, while the value of the " +
  3. "integer variable is %d, and the string is %s", floatVar, intVar, stringVar);
  4. System.out.println(fs);
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 55
Reputation: mickinator is an unknown quantity at this point 
Solved Threads: 5
mickinator mickinator is offline Offline
Junior Poster in Training

Re: How do you output in two columns?

 
0
  #3
Nov 6th, 2007
That method is pretty similar to the printf() method of String. What you could also do is, if you only have a couple of things, you could tab them, ie:
System.out.println( "Blah\tBlah" ); would give you an output like:

Blah Blah
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,281
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 243
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: How do you output in two columns?

 
0
  #4
Nov 6th, 2007
As long as the first String is always of the same length and does not vary over the "tabStop index" length. printf (if you're using a late enough version of it) is, of course, the proper way to do this.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 8
Reputation: Amurka is an unknown quantity at this point 
Solved Threads: 0
Amurka Amurka is offline Offline
Newbie Poster

Re: How do you output in two columns?

 
0
  #5
Nov 6th, 2007
This is a lot easier than when I first looked at it. I made the first column stuff string and took there length, then from that added the necessary spaces. Kind of easy. Thanks for the help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC