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.

Results 1 to 4 of 4

Thread: i am very stuck on this

  1. #1
    Junior Member
    Join Date
    Jan 2018
    Posts
    5
    My Mood
    Aggressive
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Angry Put data into an array

    can someone please help me solve this for me:

    Read in a text file called repeat.txt, consisting integer numbers. Convert the text
    numbers into INTEGER and store them into an ARRAY. Max number of numbers in
    the file is 25, one number per line.
    Input File Example:
    1
    2
    2
    3
    4
    4
    5
    5
    5

    A repeat in an array is a series of 2 or more adjacent elements of the same value.
    Return the number of repeats in the given array.
    Sample output. Several possibilities are presented

    Counting Repeats
    ===========
    [1, 2, 2, 3, 4, 4] = 2

    Counting Repeats
    ===========
    [1, 1, 2, 1, 1] = 2

    Counting Repeats
    ===========
    [1, 1, 1, 1, 1] = 1

    I have set up the import code but I don't know how to put the numbers in the import file into the array

    Sorry for reposting this problem again, but I found one of the things that I don't know how to do:
    How do I send data to an array after I set up my buffered reader?


    Read in a text file called repeat.txt, consisting integer numbers. Convert the text
    numbers into INTEGER and store them into an ARRAY. Max number of numbers in
    the file is 25, one number per line.
    Input File Example:
    1
    2
    2
    3
    4
    4
    5
    5
    5

    A repeat in an array is a series of 2 or more adjacent elements of the same value.
    Return the number of repeats in the given array.
    Sample output. Several possibilities are presented

    Counting Repeats
    ===========
    [1, 2, 2, 3, 4, 4] = 2

    Counting Repeats
    ===========
    [1, 1, 2, 1, 1] = 2

    Counting Repeats
    ===========
    [1, 1, 1, 1, 1] = 1
    Last edited by Norm; January 12th, 2018 at 08:01 AM. Reason: Same topic

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,237
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: i am very stuck on this

    What have you tried?

    Be sure to wrap any posted code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,237
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: i am very stuck on this

    how to put the numbers in the import file into the array
    Use a Scanner class's method to read the file
    and use an assignment statement to put the data into the array.
    Wrap the code in a loop to read the data and assign it to slots in the array.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,237
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: i am very stuck on this

    How do I send data to an array
    Use an assignment statement:
       theArray[theIndex] = theValue;   // assign a value to a slot in array
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Please Help I'm stuck
    By mael331 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 6th, 2011, 09:02 AM
  2. Im stuck, please help
    By bigsmoke101 in forum Loops & Control Statements
    Replies: 3
    Last Post: April 12th, 2011, 04:34 PM
  3. Stuck again
    By Tate in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 28th, 2010, 10:22 AM
  4. Stuck help please!
    By mindlessn00b in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 5th, 2010, 05:31 PM
  5. I am stuck
    By hawkman4188 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 29th, 2010, 12:46 AM

Tags for this Thread