Results 1 to 9 of 9
  1. #1
    o0oNorao0o's Avatar
    o0oNorao0o is offline Member
    Join Date
    Oct 2009
    Posts
    51
    Rep Power
    0

    Red face I want the output to be apper HORIZONTALLY

    Hi
    I want the output to be appear horizontally rather than vertically:o
    I mean I want the columns as you see in the picture beside each other not under each other:o
    Attached Thumbnails Attached Thumbnails I want the output to be apper HORIZONTALLY-output.jpg  

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Then rather than using three loops with a println call for each element you need to access all three values from one loop and use printf.

  3. #3
    o0oNorao0o's Avatar
    o0oNorao0o is offline Member
    Join Date
    Oct 2009
    Posts
    51
    Rep Power
    0

    Default

    I don't get it sorry (I'm still beginner in Java):shy:
    here is the program
    Java Code:
    public class aster
    {
    	public static void main (String [] args)
    	{
    		int [] arr = {13,2,9,6,1,17,4};
    			System.out.println("Element ");
    			
    			
    		for (int i=0 ; i<arr.length;i++)
    		{
    			System.out.println(i);
    		
    		}
    	
    		System.out.println("Values");
    		for (int i=0 ; i<arr.length;i++)
    		{
    			System.out.println(arr[i]);
    		
    		}
    			System.out.println("Graphically");
    			
    			for (int i=0 ; i<arr.length;i++)
    			{
    				System.out.println();
    				
    				for (int star=0 ; star<arr[i];star++)
    				{
    					System.out.print('*');
    				}
    					
    			}
    		
    	}
    }

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    So try to implement what I suggested (if you don't want to bother with printf then use simple println, but printf would be cleaner, see the API docs). As you can see, you currently have 3 "for (int i =" loops, you need to do all three of those actions in a single loop with a single print statement.

  5. #5
    o0oNorao0o's Avatar
    o0oNorao0o is offline Member
    Join Date
    Oct 2009
    Posts
    51
    Rep Power
    0

    Default

    How can I write the column name above each one

    Java Code:
    	
    		for (int i=0 ; i<arr.length;i++)
    		{
    			System.out.print(i +"\t"+ arr[i]);
    			
    				System.out.print("\t");
    				for (int star=0 ; star<arr[i];star++)
    				{
    					
    					System.out.print('*');
    					
    				}
    			
    		System.out.println();
    		}
    Is that what you mean ?
    Last edited by o0oNorao0o; 01-21-2010 at 10:55 AM.

  6. #6
    o0oNorao0o's Avatar
    o0oNorao0o is offline Member
    Join Date
    Oct 2009
    Posts
    51
    Rep Power
    0

    Default

    Java Code:
    System.out.print ("Element");
    	  System.out.print ("\t"+"Values");
    	  System.out.println ("\t"+"Graphically");
    it appears like that :(:(
    Attached Thumbnails Attached Thumbnails I want the output to be apper HORIZONTALLY-output.jpg  

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    That was why I suggested printf and suggested a single println as the alternative. You do know how to concatenate Strings, right? See the API docs for the printf method (and make sure to follow the link to the format string page).

    Java Code:
    "%7d %6d %s\n"
    (assuming a single space between the "headers")
    Last edited by masijade; 01-21-2010 at 11:16 AM.

  8. #8
    o0oNorao0o's Avatar
    o0oNorao0o is offline Member
    Join Date
    Oct 2009
    Posts
    51
    Rep Power
    0

    Default

    Where should I put this code "%7d %6d %s\n"?
    yeah I know how to join multiple Strings

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by o0oNorao0o View Post
    Where should I put this code "%7d %6d %s\n"?
    printf See the API docs already. If you had done that you wouldn't need to ask this!

    printf is part of PrintStream which is what System.out is. format is part of String, and would also work (combined with println, of course).

Similar Threads

  1. NaN output?
    By bigj in forum New To Java
    Replies: 2
    Last Post: 01-06-2010, 09:32 AM
  2. what is this output?
    By bigj in forum New To Java
    Replies: 5
    Last Post: 01-04-2010, 05:07 PM
  3. How to duplicat drawOval horizontally?
    By ntagrafix in forum AWT / Swing
    Replies: 1
    Last Post: 12-03-2009, 09:37 PM
  4. Can anyone tell me how this output?
    By vysh in forum Advanced Java
    Replies: 16
    Last Post: 05-10-2009, 08:32 PM
  5. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM

Posting Permissions

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