Results 1 to 2 of 2

Thread: Boolean

  1. #1
    must0995 is offline Member
    Join Date
    Apr 2012
    Posts
    7
    Rep Power
    0

    Default 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.
    Java 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;
              
             
                
            }     
        }
    
    }
    Last edited by JosAH; 04-13-2012 at 10:01 PM. Reason: added [code] ... [/code] tags

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,581
    Rep Power
    25

    Default 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?
    Last edited by Norm; 04-13-2012 at 10:20 PM.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 09-13-2011, 12:01 AM
  2. boolean error help when no boolean is given
    By drewtrcy in forum New To Java
    Replies: 18
    Last Post: 05-05-2011, 09:04 AM
  3. boolean even or odd?
    By shazakala in forum New To Java
    Replies: 3
    Last Post: 04-17-2011, 08:02 AM
  4. Boolean help
    By DMarsh12 in forum New To Java
    Replies: 8
    Last Post: 04-11-2011, 09:41 PM
  5. use boolean as 0 or 1
    By joost_m in forum New To Java
    Replies: 10
    Last Post: 04-13-2010, 11:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •