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!
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] + "");
}
}
}
}
Re: Help with output display please
So maybe things arent happening in the right order.
Re: Help with output display please
Quote:
Originally Posted by
jammas615
So maybe things arent happening in the right order.
i dont understand...what can possibly be out of order?
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.
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.