jebril's Profile
Reputation: -4
Dishonored
- Group:
- Members
- Active Posts:
- 32 (0.08 per day)
- Joined:
- 24-March 12
- Profile Views:
- 302
- Last Active:
Jun 07 2012 12:06 PM- Currently:
- Offline
Previous Fields
- Country:
- Who Cares
- OS Preference:
- Who Cares
- Favorite Browser:
- Chrome
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- PC
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: always display 0
Posted 7 Jun 2012
-
In Topic: always display 0
Posted 7 Jun 2012
-
In Topic: always display 0
Posted 7 Jun 2012
pbl, on 06 June 2012 - 02:11 PM, said:Works for me
public static void main(String[] args) { int[] enter = {1,4,5,6,5,4,3,2,2,3,4,5}; int[] distinct = new int[enter.length]; int count=0; boolean found=false; for( int i=0 ; i<enter.length; i++){ for( int j=0; j<count;j++){ if(enter[i]==distinct[j]){ found=true; break; } } if(found==false){ distinct[count++]=enter[i]; System.out.print(" " + enter[i]); found = false; } } }
but it doesn't show the number 2 and 3
any more idea?
-
In Topic: always display 0
Posted 6 Jun 2012
-
In Topic: always display 0
Posted 6 Jun 2012
pbl, on 06 June 2012 - 01:00 PM, said:Your add to count++ should be done onece the loop is completed, not a each iteration
and you have to reset found
public class distinct { int count=0; boolean found=false; for( int i=0 ; i<enter.length; i++){ for( int j=0; j<count;j++){ if(enter[i]==distinct[j]){ found=true; break; } } if(found==false){ distinct[count++]=enter[i]; found = false; } return distinct; }
it still there is an error ! for example if i enter:
Enter 10 integers: 1 2 3 4 2 1 6 3 1 2
distinct are:
1 2 3 4 0 0 0 0 0 0 <----- it dont put the 6!! any idea?
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
Contact Information
- E-mail:
- Private
- Website URL:
-
http://www.anarchyhome.wordpress.com
Friends
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
jebril has no profile comments yet. Why not say hello?