Read from the Scanner into variables, print the value of the variable and then use that variable where the call to the Scanner class methods are now.

February 21st, 2013, 01:24 PM

ajw1993

Re: Im having trouble storing ints that have been converted at the end of a line in a file into a 2d array.

when does the delimiter come into use because i need to use it

February 21st, 2013, 01:31 PM

Norm

Re: Im having trouble storing ints that have been converted at the end of a line in a file into a 2d array.

That part of the code is not changed. The change is removing the calls to Scanner methods to a separate line,
printing what was read and then the value read is used where the calls to the Scanner methods were.

February 21st, 2013, 01:41 PM

ajw1993

Re: Im having trouble storing ints that have been converted at the end of a line in a file into a 2d array.

could u show me what u mean kinda making it confusing ive only just started in sept thats why im having trouble
Scanner scanner2 = new Scanner(scanner.nextLine());
scanner2.useDelimiter("[ ]*(,)[ ]*");

February 21st, 2013, 01:49 PM

Norm

Re: Im having trouble storing ints that have been converted at the end of a line in a file into a 2d array.

Code :

String aStr = scanner.nextLine(); // read next line into a variable
System.out.println("aStr="+aStr); // show what was read
Scanner scanner2 = new Scanner(aStr); // set the Scanner to use the line

February 21st, 2013, 01:58 PM

ajw1993

Re: Im having trouble storing ints that have been converted at the end of a line in a file into a 2d array.

testMarks[add][columns + num] = scanner.nextInt(); - still null , but prints out the first line of the file

February 21st, 2013, 02:07 PM

Norm

Re: Im having trouble storing ints that have been converted at the end of a line in a file into a 2d array.

what does "still null" mean? If there are error messages, copy the full text and print them.

Re: Im having trouble storing ints that have been converted at the end of a line in a file into a 2d array.

i do need to use the delimiter tho to suit the file above tho
1. need to use the delimiter
2. i need to read in all the ints on the lines in the file and store them in the 2d array
3. i need to change the strings at the end of the line and store them in the 2d array
these are what i need to do

February 21st, 2013, 02:19 PM

Norm

Re: Im having trouble storing ints that have been converted at the end of a line in a file into a 2d array.

Quote:

need to use the delimiter

Use the scanner variable to call the useDelimiter() method:

Code :

scanner2.useDelimiter("[ ]*(,)[ ]*");

This was a problem I talked about in the other thread: The code chained together too many method calls in one statement instead of having one method call per statement.

February 21st, 2013, 02:23 PM

ajw1993

Re: Im having trouble storing ints that have been converted at the end of a line in a file into a 2d array.

so how do i the other two , cz of the commas n etc they are the problem