# Boolean

• 04-13-2012, 09:55 PM
must0995
Boolean
Hi there is problem with my private boolean true;
the quastion is , i want to return true of there is Unique number in array. if all not same , it should return false.
Code:

```public class k7exr11 {     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};                         isUnique(a);             isUnique(b);                     }     public static boolean isUnique(int[] a) {                 privat boolean result;         for (int i = 1; i < a.length; i++) {                                           if(a[i] == a[i-1] ){                             result = false;                             } else{                                 result = true;             }             return result;                                       }        } }```
• 04-13-2012, 10:18 PM
Norm
Re: Boolean
Add a println in the loop that prints out the value of i and the value of results to see how many times the loop goes around and to see how the value of result changes as it loops

You need to work on the logic for the method. What are the steps the code must take to do its job? What if you had some playing cards in a pile and wanted to know if all the cards in the pile are unique? How would you do it?