# Thread: Printing repeating integers in an array problem!

1. Member
Join Date
Aug 2012
Posts
8
Rep Power
0

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

Originally Posted by Norm
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. ## 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?

3. Member
Join Date
Jun 2012
Posts
73
Blog Entries
1
Rep Power
0

## 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. ## 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.

5. Student
Join Date
Jul 2012
Location
United States
Posts
328
Rep Power
5

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

Originally Posted by .paul.
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.

6. Member
Join Date
Jun 2012
Posts
73
Blog Entries
1
Rep Power
0

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

Originally Posted by .paul.
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. Member
Join Date
Jun 2012
Posts
73
Blog Entries
1
Rep Power
0

## 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. Student
Join Date
Jul 2012
Location
United States
Posts
328
Rep Power
5

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

Originally Posted by .paul.
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.

9. ## Re: Printing repeating integers in an array problem!

Originally Posted by .paul.
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. Member
Join Date
Jun 2012
Posts
73
Blog Entries
1
Rep Power
0

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

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. Student
Join Date
Jul 2012
Location
United States
Posts
328
Rep Power
5

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

Originally Posted by .paul.
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.

12. Moderator
Join Date
Apr 2009
Posts
13,069
Rep Power
23

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

Originally Posted by .paul.
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".

13. Member
Join Date
Sep 2014
Posts
1
Rep Power
0

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

Originally Posted by .paul.
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. ## Re: Printing repeating integers in an array problem!

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

Jos

Page 2 of 2 First 12

#### Posting Permissions

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