Page 2 of 2 FirstFirst 12
Results 21 to 34 of 34
Like Tree2Likes

Thread: Printing repeating integers in an array problem!

  1. #21
    andrewk1978 is offline Member
    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Default Re: Printing repeating integers in an array problem!

    Quote Originally Posted by Norm View Post
    Can the contents of the array be changed?
    Seems the problem is how to keep track of what numbers have been counted. Could a method that scans the array determine if a number has already been counted?
    no unfortunatley. no changes to the arrays and no sorting and no new arrays. got me stumped.

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default Re: Printing repeating integers in an array problem!

    Have you thought how to solve this: how to keep track of what numbers have been counted
    Say you have counted the first 3 numbers and are now looking at the 4th number. What could tell you if that number has been counted yet? Hint: what about the numbers that precede the 4th number?
    If you don't understand my response, don't ignore it, ask a question.

  3. #23
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing repeating integers in an array problem!

    i don't want to give you working code as it seems effort isn't rewarded in this forum. so here's some pseudocode:

    for loop1 = 0 to end of array
    variable num = yourArray elementAt(loop1)
    variable previousCounter = 0
    for loop2 = 0 to loop1 - 1
    if num = yourArray elementAt(loop2) then previousCounter +=1
    next
    if previousCounter = 0 then
    variable counter = 0
    for loop3 = loop1 + 1 to end of array
    if num = yourArray elementAt(loop3) then counter +=1
    next
    output result
    end if
    next

    if that's spoon feeding then i don't want to be part of this time wasting forum

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default Re: Printing repeating integers in an array problem!

    Why don't you give the OP a chance to work out the logic? Get the OP to post his pseudo code and then give hints to move it to a solution.
    Again your posting does not give an overview of how it works. It just goes into the details.
    Sometimes it seems that you want to show off rather than help the OP get the solution on his own.
    If you don't understand my response, don't ignore it, ask a question.

  5. #25
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Printing repeating integers in an array problem!

    Quote Originally Posted by .paul. View Post
    i don't want to give you working code as it seems effort isn't rewarded in this forum.

    if that's spoon feeding then i don't want to be part of this time wasting forum
    To the contrary, effort is rewarded on this forum. It takes more effort to guide someone to enlightenment over a particular issue or problem through explanation than to simply toss him the solution.

    I've only been on this forum for about a month, but it seems to me that this forum focuses on helping people understand how to code in Java, not what to type in order to get a certain result. It's more beneficial for a person to learn how to solve a problem and then solve the problem on his own rather than to be given the solution.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  6. #26
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing repeating integers in an array problem!

    Quote Originally Posted by .paul. View Post
    you need an outer loop that iterates from 0 through the array
    inside that loop you need to loop from 0 to outer - 1 + test if your current number has already been counted
    if not already counted then an inner loop that iterates from outer + 1 through the array + counts reoccurences of your current number
    @Norm. above, as posted in post#9

  7. #27
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing repeating integers in an array problem!

    just as a FYI... i'd rather be finding answers than sitting around scratching my head + wondering for 3 or 4 days. but that's just me. maybe you people enjoy that.

  8. #28
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Printing repeating integers in an array problem!

    Quote Originally Posted by .paul. View Post
    just as a FYI... i'd rather be finding answers than sitting around scratching my head + wondering for 3 or 4 days. but that's just me. maybe you people enjoy that.
    Surely nobody enjoys being confused. However, spoon-feeding is not an effective way to purge confusion. It is a temporary solution to a singular problem because it lacks foresight.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  9. #29
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Printing repeating integers in an array problem!

    Quote Originally Posted by .paul. View Post
    i don't want to give you working code as it seems effort isn't rewarded in this forum.
    I'm sorry but I didn't realise we were supposed to give you a pat on the back. The issue is not if YOU can solve the problem but if the OP can solve it. If you simply spoonfeed them the code did they solve it? No and if they hand your work in as their own it is called academic dishonesty.

  10. #30
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing repeating integers in an array problem!

    ok. using your own analogy.
    you spoonfeed a baby... what happens??? eventually the baby learns to do it for theirself.

    if you push a baby off a cliff would you expect it to fly???

    beginning programming can be daunting + not everyone learns in a regular linear way.
    maybe i should've advised sitting down with a piece of paper + working out an algorithm, but noone else advised that either.

  11. #31
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Printing repeating integers in an array problem!

    Quote Originally Posted by .paul. View Post
    ok. using your own analogy.
    you spoonfeed a baby... what happens??? eventually the baby learns to do it for theirself.

    if you push a baby off a cliff would you expect it to fly???

    beginning programming can be daunting + not everyone learns in a regular linear way.
    maybe i should've advised sitting down with a piece of paper + working out an algorithm, but noone else advised that either.
    Literally spoon-feeding food into a baby's mouth and tossing a code solution at someone are not comparable because the tasks differ in requirement of cognitive ability.

    There are some basic concepts in programming that I think should be spoon-fed such as loops, conditional statements, classes and objects, ect. These aren't things that someone is going to learn on his own.

    However, once a person has these building blocks, spoon-feeding should come to an end. The main reason is because it stops being effective once the material reaches a certain complexity.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  12. #32
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Printing repeating integers in an array problem!

    Quote Originally Posted by .paul. View Post
    just as a FYI... i'd rather be finding answers than sitting around scratching my head + wondering for 3 or 4 days. but that's just me. maybe you people enjoy that.
    We are not here to provide hard coded solutions to people's homework.
    We are here to provide help to guide people to the solution.

    We do not know the level of the people asking here (though a rough guess can be made), or what it is they are working towards, but having worked with people who have clearly blagged their way through to jobs in this way, and having had to clear up after them, I'd rather not support the view that forums are here as coding services.

    Besides, handing over code solutions simply removes the eureka moment when the light goes on as a solution suddenly becomes clear. This is rather well known in training circles. It's a version of the old "teaching to fish instead of giving a fish".
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #33
    madhura lola is offline Member
    Join Date
    Sep 2014
    Posts
    1
    Rep Power
    0

    Post Re: Printing repeating integers in an array problem! :

    Quote Originally Posted by .paul. View Post
    without the HashMap:

    Java Code:
    package arraycount;
    
    /**
     *
     * @author Paul
     */
    public class ArrayCount {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            
            int[] intArray = {1,4,2,3,5,4,4,7,5,4,3,6,8,6,4};
            
            for(int outer = 0; outer < intArray.length; outer++){
                if(intArray[outer] != Integer.MIN_VALUE) {
                    int num = intArray[outer];
                    intArray[outer] = Integer.MIN_VALUE;
                    int counter = 1;
                    for(int inner = outer + 1; inner < intArray.length; inner++){
                        if(intArray[inner] == num){
                            counter++;
                            intArray[inner] = Integer.MIN_VALUE;
                        }
                    }
                    System.out.println("Integer: " + num + ", Times: " + counter);
                }            
            }
            
        }
    }
    Why Integer.MIN_VALUE is used in this program.please explain

  14. #34
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Printing repeating integers in an array problem!

    This thread is more than two years old; it deserves to be left alone.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 4
    Last Post: 01-27-2012, 12:18 PM
  2. Replies: 7
    Last Post: 04-22-2011, 12:40 PM
  3. Printing repeating integers in a given array?
    By baumboards in forum New To Java
    Replies: 7
    Last Post: 01-24-2011, 08:08 PM
  4. Non-Repeating Random Integers
    By Psyclone in forum New To Java
    Replies: 5
    Last Post: 01-31-2010, 10:04 PM
  5. Problem printing an array
    By denial in forum New To Java
    Replies: 3
    Last Post: 11-01-2009, 11:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •