StringTokenizer and substring method
src des cos
011
022
111
123
while(hasMoreTokens)
{
src = nextToken;
des = nextToken;
cost = nextToken;
String a = src + des + cost;
}
int [] [] array = new int[ i ] [ j ]
Since I'm using tokens, I just want to take the cost and put it in a 2D array.
Can I use the substring on a.substring (2,3) to get the cost and assign it to the array?
[432 byte] By [
javaeta] at [2007-11-26 15:23:38]

> src des cos
> 011
> 022
> 111
> 123
>
> while(hasMoreTokens)
> {
> src = nextToken;
> des = nextToken;
> cost = nextToken;
> String a = src + des + cost;
> }
> int [] [] array = new int[ i ] [ j ]
> Since I'm using tokens, I just want to take the cost
> and put it in a 2D array.
> Can I use the substring on a.substring (2,3) to get
> the cost and assign it to the array?
You already have each individual cost in the cost variable as you loop; why not put them in the array at that time. If you do not know how many there will be before hand, use an ArrayList.
This looks to be a graph definition. You can split each line using
String[] splitLine = line.split("\s+");
Then
int src = integer.parseInt(splitLine[0]);
int des = integer.parseInt(splitLine[1]);
int cos = integer.parseInt(splitLine[2]);
You can then use value these to populate your cost matrix.