
write a java method that takes an array of float values and determines if all the numbers are different from each other ( thay are distinct)

Hi Friend,
Try the following code:
import java.util.*;
class CheckDuplicateArrayValue{
public static void main(String args[]){
float [] arr = new float[]{1,2,2,7,9};
if(checkDuplicates(arr)){
System.out.println("There are duplicate elements.");
Float array[] = new Float[arr.length];
for(int i=0;i<arr.length;i++){
array[i]=new Float(arr[i]);
}
Set<Float> set=new HashSet<Float>(Arrays.asList(array));
System.out.print(set);
}
else{
System.out.println("No duplicate elements are there!");
}
}
private static boolean checkDuplicates(float[] array){
for (int i = 0; i < array.length; i++) {
float num = array[i];
if(num==0)continue;
for (int j = 0; j < array.length; j++) {
if(i==j)continue;
float compnum = array[j];
if (num==compnum){
return true;
}
}
}
return false;
}
}
Thanks

Thanks...I need a simple program without hashset.Do you have any idea?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.