Question 1 public static void main(String[] args) { int[] array = {1,2,3,4,5,6}; //boolean result = isUnique(array); System.out.print(isUnique(array)); } public static boolean isUnique(int[] array) { int value; for(int i=0; i<array.length; i++) { value = array[i]; for(int j=i+1; j<array.length; j++) { if(value == array[j]) { return false; } } } return true; } } //OUTPUT: true public static void main(String[] args) { int[] array = {2,2,3,4,5,6}; //boolean result = isUnique(array); System.out.print(isUnique(array)); } public static boolean isUnique(int[] array) { int value; for(int i=0; i<array.length; i++) { value = array[i]; for(int j=i+1; j<array.length; j++) { if(value == array[j]) { return false; } } } return true; } } //OUTPUT: false
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter