Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Displaying Distinct Numbers from Array

array

  • Please log in to reply
1 reply to this topic

#1 ahwoo

ahwoo

    CC Newcomer

  • Member
  • PipPip
  • 16 posts
  • Programming Language:Java
  • Learning:Java

Posted 10 October 2012 - 08:44 AM

Hey everyone again,

I'm trying to display 3 distinct integers from user input

the length of the array is also 3

so for example:

1, 1, 2, 3, 4

the distinct set would be 2,3,4

Here is what I have so far, however at the moment it is terminating after the I input data the 3rd time, and not letting me collect all 3 unique numbers before printing
  • 0

#2 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 10 October 2012 - 09:00 AM

I think the problem is here
for (int i = 0; i < numbers.length-1; i++) {

change to
for (int i = 0; i < numbers.length; i++) {


from:
for (int j = i+1; j < numbers.length; j++) {
to:
for (int j = i+1; j < numbers.length-1; j++) {

give it a try
  • 0

www.pickmike.com
I don't just develop software. I find solutions to your business needs.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download