Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method called isUnique that accepts array of integers as a parameter and

ID: 3622253 • Letter: W

Question

Write a method called isUnique that accepts array of integers as a parameter and returns a boolean value indicating whether or not the values in the array are unique (true for yes, false for no). The values in the list are considered unique if there is no pair of values that are equal. For example, if passed an array containing {3, 8, 12, 2, 9, 17, 43, -8, 46}, your method should return true, but if passed {4, 7, 3, 9, 12, -47, 3, 74}, your method should return false because the value 3 appears twice.

Explanation / Answer

please rate - thanks

import java.util.*;
public class array
{public static void main(String[] args)
{int a[]={3, 8, 12, 2, 9, 17, 43, -8, 46};
int b[]={4, 7, 3, 9, 12, -47, 3, 74};
if(isUnique(a))
     System.out.println("{3, 8, 12, 2, 9, 17, 43, -8, 46} is unique");
else
     System.out.println("{3, 8, 12, 2, 9, 17, 43, -8, 46} is not unique");
if(isUnique(b))
     System.out.println("{4, 7, 3, 9, 12, -47, 3, 74} is unique");
else
     System.out.println("{4, 7, 3, 9, 12, -47, 3, 74} is not unique");
   

}
public static boolean isUnique(int a[])
{int i,j;
for(i=0;i<a.length-1;i++)
   for(j=i+1;j<a.length;j++)
         if(a[i]==a[j])
             return false;   
return true;               
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote