Write a static method named repeats_exist(numbers) that takes an array of integers as a parameter and returns true if there are any repeated values in the array, and false if all of the values in the array are unique. Note: you can assume that the array is not empty and the method returns a boolean value.
For example:
Test Result
System.out.println(repeats_exist(new int[]{2, 3, 4, 5, 6})); false
System.out.println(repeats_exist(new int[]{2, 3, 4, 3, 6})); true
Here is my attempt, but still have an error. Please help me to fix the problem.
static boolean repeats_exist(int a[],int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
return true;
}
}
return false;
}