Results 1 to 4 of 4
  1. #1
    DMarsh12 is offline Member
    Join Date
    Mar 2011
    Posts
    43
    Rep Power
    0

    Default Help with output display please

    I am writing a northwest corner program and I have the data output I want but it needs to be in a table format. The output should be as follows

    100 50 50
    0 150 200
    0 0 50

    My output is

    --------------------Configuration: <Default>--------------------
    100
    0
    0
    50
    150
    0
    50
    200
    50

    Any help would be greatly appreciated!

    Java Code:
    public class NorthwestCorner {
    
        public static void main(String[] args) {
    
        	int s[]={100, 200, 300};
    		int d[]={150, 350, 100};
    
    		int [][]table=new int[s.length][d.length];
    		for (int i=0;i<=s.length-1;i++)
    			{int totalsupply=s[i];
    
    		for (int j=0;j<=d.length-1;j++)
    		{int totaldemand=d[j];
    
    		if (s[i]>d[j]){
    			table[i][j]=d[j];
    			s[i]=s[i]-d[j];
    		}
    			else{
    				table[i][j]=s[i];
    				d[j]=d[j]-s[i];
    				s[i]=0;
    }
    		System.out.println(table[i][j] + "");
    }
    			}
        }
    }
    Last edited by DMarsh12; 10-08-2011 at 05:19 AM.

  2. #2
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default Re: Help with output display please

    So maybe things arent happening in the right order.

  3. #3
    DMarsh12 is offline Member
    Join Date
    Mar 2011
    Posts
    43
    Rep Power
    0

    Default Re: Help with output display please

    Quote Originally Posted by jammas615 View Post
    So maybe things arent happening in the right order.
    i dont understand...what can possibly be out of order?

  4. #4
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default Re: Help with output display please

    Oooh, i see what you mean now. Your println(); only prints ONE value at a time, and you want to have an output that looks like a table. So, you need to output a whole row at a time. Somehow, your println(); needs to only run 3 times and each time print a whole row.
    This will give you the output you want.
    Java Code:
    System.out.println("100 50 50");
    System.out.println("0 150 200");
    System.out.println("0 0  50");
    Now your going to need to sit down and redesign so your printing line by line.

Similar Threads

  1. Netbeans output window won't display
    By jujubinaj in forum New To Java
    Replies: 1
    Last Post: 12-16-2010, 03:51 AM
  2. How to display Output String in asterix?
    By shalini_priya in forum New To Java
    Replies: 1
    Last Post: 11-24-2009, 12:36 PM
  3. Replies: 0
    Last Post: 11-17-2009, 07:36 PM
  4. Display output in Jframe or JPanel
    By rammurugesan in forum AWT / Swing
    Replies: 12
    Last Post: 04-14-2009, 02:45 PM
  5. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-26-2009, 12:44 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
  •