Results 1 to 6 of 6
  1. #1
    siah0wn5a11 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Question Table formating in command line

    I am doing a project of converting from feet to meters and vice versa. I have everything done that it needs to do but the example table for the assignment has these 2 listed side by side. I only know how to list them one on top of the other. Can somone plz help with this. You can run my code to better understand what i mean.
    Java Code:
    public class Conversion
    {
    	public static void main(String[] args)
    	{
    		double foot = 0;
    		double meter = 0;
    		footToMeter(foot);
    		System.out.println();
    		System.out.println();
    		meterToFoot(meter);
    	}
    	public static  double footToMeter(double foot)
    	{
    		System.out.println("Feet" + "\t" + "Meters");
    			for (foot=1;foot<=10;foot++)
    			{
    				double meter = 0.305 * foot;
    				System.out.println(foot + "\t" + meter);
    			}
    	return foot;
    	}
    	public static double meterToFoot(double meter)
    	{
    		meter = 0;
    		System.out.println("Meter" + "\t" + "Feet");
    			for (meter=1; meter<=10;meter++)
    			{
    				double foot = 3.281 * meter;
    				System.out.println(meter + "\t" + foot);
    			}
    	return meter;
    	}
    }
    It needs to be Feet Meters|Meters feet Thanks

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Table formating in command line

    Sounds like you need the printf method.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Table formating in command line

    siah0wn5a11, you didn't bother to return to your previous thread: Displaying Array Statistics Inside One JOptionPane

    Can we expect better behavior this time round?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    siah0wn5a11 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Default Re: Table formating in command line

    I have no knoledge of printf. Could someone please help me with that?

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Table formating in command line

    I mentioned a method that you do not know about. Do you think looking it up in the API might be a good place to start. I give you a start, it is in the PrintWriter class (same as the print and println methods). Once you have read about it you could Google for some examples. Once that is done try writing a simple test class and if you have trouble with that then come back and ask for help.

  6. #6
    siah0wn5a11 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Default Re: Table formating in command line

    I just rewrote my code using arrays and printf. Thanks for help.

Similar Threads

  1. Replies: 4
    Last Post: 01-02-2013, 08:50 PM
  2. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  3. can i run line by line command in netbean?
    By choconlongxu in forum NetBeans
    Replies: 1
    Last Post: 07-19-2010, 08:41 PM
  4. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •