Results 1 to 2 of 2
  1. #1
    and0rsk is offline Member
    Join Date
    Oct 2010
    Posts
    6
    Rep Power
    0

    Default Problem with code

    I have a method that seems to have a problem with it. Could you please point to me where I went wrong. The error is dead code and the method must return type boolean.
    Java Code:
    public static boolean contains(int[] A, int int1){
    for (int i = 0; int ,i < A.length; i++) {
            if (int1 == A[i])
    return true;
    }
    else {return false;}
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by and0rsk View Post
    Java Code:
    public static boolean contains(int[] A, int int1){
    for (int i = 0; int ,i < A.length; i++) {
            if (int1 == A[i])
    return true;
    }
    else {return false;}
    }
    }
    What is that second 'int' doing there in the header of your for-loop? When the loop has finished your method isn't returning anything.

    b.t.w. your indentation sucks.

    kind regards,

    Jos

Similar Threads

  1. Replies: 9
    Last Post: 09-21-2010, 05:15 PM
  2. problem in my code
    By wannabe in forum New To Java
    Replies: 5
    Last Post: 04-12-2010, 05:38 AM
  3. Problem my code..
    By Miyaki in forum New To Java
    Replies: 3
    Last Post: 03-09-2009, 01:36 AM
  4. Help me!!!!!!!! Problem with Code!!
    By Miyaki in forum New To Java
    Replies: 0
    Last Post: 03-08-2009, 01:26 AM
  5. Problem with code
    By oregon in forum New To Java
    Replies: 3
    Last Post: 08-05-2007, 06:57 PM

Posting Permissions

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