Monday, 9 September 2013

Converting elements of String[] to Scanner object

Converting elements of String[] to Scanner object

I'm new to Java, and what I've been trying to do:
tempTrailerArris a String[] = {"12.0 1.1", "24.51", "34.12", "82.87 231.2
1.1 2.2"}
Each element of tempTrailerArr is converted into a Scanner object trScan.
The first double of each element in tempTrailerArr is to be stored in a
Double[] called trailerVals.
So the desired result would be for tempTrailerArr = {12.0 24.51 34.12 82.87}
However, the code below won't terminate, and I don't understand why?
for (int j=0; j<tempTrailerArr.length; j++) {
Scanner trScan = new Scanner(tempTrailerArr[j]);
switch (j) {
case 0:
case 1:
case 2:
case 3: this.trailerVals[j] = trScan.nextDouble();
break;
}
}

No comments:

Post a Comment