SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Stuart Reges, Marty Stepp
Chapter:
Arrays
Exercise:
Exercises
Question:11 | ISBN:9780136091813 | Edition: 2

Question

Write a method called isUnique that accepts an 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 con-

sidered 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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Implementation of isUnique method:

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

Discussions

Post the discussion to improve the above solution.