Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 42 of 42

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

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    Sorry, I don't know what the "other two" are. Can you post the current code with comments that shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    2. i need to read in all the ints on the lines in the file and store them in the 2d array (8 lines) (10 ints)(4 strings)
    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

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    Does this mean you are starting over with the program?
    What are the steps the new program needs to take to
    read in the first part of the lines and save the numbers in one array
    and then read the rest of the line and save it in another array?

    Can you give an example of where the data from one line will go in the arrays?
    Here is a line:
    5,5,5,6,5,8,9,5,6,8, good, very good, excellent, good

    How will the code put the first part into one array and the second part into another array?

    Do all the lines have the same count of numbers and Strings?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    yeah i have to read in the line in the array testMarks[add][the line of ints and converted ints]
    - in the add bit is the line that it is in as it is being stored
    if u know what i mean , but they have to be stored in the same 2d array

    yh each has 10 ints then 4 strings that have be converted using the switch statement

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    Do you have code for the new program? The old code doesn't do what you want.
    but they have to be stored in the same 2d array
    The new program needs a second array to hold the Strings
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    i have to change the strings into ints via the switch statement i dont wana store the strings themselves

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    Please explain what the problems are.

    The current code does not do what you want. It needs to be rewritten to do the things you want:
    1). read in all the ints on the lines in the file and store them in the 2d array
    2) change the strings at the end of the line and store them in the 2d array
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    thats what i want it to do , so what do i need to do in that method to ensure that works ??

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    what do i need to do in that method to ensure that works
    Start by designing what the method should do. Make a list of the steps(simple steps) that the code needs to do.
    When you get a good design, then try coding it in small steps, with testing of each step and printing out the results of each step. When one step is working, add the code for the next step and repeat the process.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #35
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    its just in the for loops the start of the method is what i want so thats find its what happens in the for loops thats the problem

  11. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    The code needs to be redone. You need a new design and new code.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #37
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    how would i just change the end of the line and store the ints that have been converted ?

  13. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    Here's a start on the design:
    init file for scanning
    begin loop to read lines from file
    read a line from file and print it for debug
    1). read in all the ints on the lines in the file and store them in the 2d array
    init scanner to delimit tokens in line

    begin loop to scan the line

    begin loop to read numbers from line
    read next number
    store number in array
    end loop reading numbers

    2) change the strings at the end of the line and store them in the 2d array
    begin loop to read strings from end of line
    read string and print for debug
    convert string
    store results in array
    end loop reading strings from line

    end loop to scan a line
    end loop to read lines from file
    If you don't understand my answer, don't ignore it, ask a question.

  14. #39
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    is that part one > for(int add=0; add<responces; add++)
    {
    for (int columns =0; columns<10; columns ++){

    testMarks[add][columns] = scanner.nextInt();
    }

    --- Update ---

    n how do i read the ints on the line if they are all have commas after them

  15. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    how do i read the ints on the line if they are all have commas after them
    Use the Scanner class's useDelimiter() method. There was one in the earlier posted code.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #41
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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 + i] = ( scanner2.nextInt(); ) < what would go there to make it not null

  17. #42
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    What variable is null?
    testMarks or scanner2
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 0
    Last Post: October 29th, 2012, 12:17 AM
  2. Reading into a File and storing it into an Array
    By loui345 in forum What's Wrong With My Code?
    Replies: 16
    Last Post: October 21st, 2012, 10:48 PM
  3. Reading a txt file and storing them in a Java Array
    By FrozenFox in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: July 27th, 2012, 07:19 AM
  4. Trouble Reading Line in File
    By Mandraix in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 4th, 2011, 10:47 PM
  5. How can I detect the end of a line in a file ?
    By lumpy in forum Java Theory & Questions
    Replies: 3
    Last Post: February 18th, 2010, 03:13 AM