Results 1 to 4 of 4
  1. #1
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

    Exclamation i have a small error but i can't figure out what is wrong [code provided]

    So I am making a class and I can't figure out why there is an error.
    The error is on the conditional of the last if statement.
    Eclipse is telling me this:

    The operator && is undefined for the argument type(s) int, boolean

    Java Code:
    	public static int search(int[] searchThisArray, int keyValue){
    		int negative1 = -1;
    		for (int i = 0; i < searchThisArray.length; i++){
    			if (searchThisArray[i] == keyValue){
    				return i; 
    				break;
    				//Will this break out of the for loop or only the if statement?????????????????????????????????
    			}
    			if ((i = ((searchThisArray.length) - 1)) && (searchThisArray[i] != keyValue))
    				return negative1;
    		}
    	}

  2. #2
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

    Default

    there is also a question inside of my code as well in the form of a comment
    all help is greatly appreciated :]

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Use == to compare, and = to assign:

    Java Code:
    if ((i == ((searchThisArray.length) - 1)) // etc

    To see what "break" does read the fine tutorial. Or just write some code to experiment.

    Post again if you get truly stuck, but the answer is on that page. (note that the labelled break statements mentioned are something to use sparingly.)

  4. #4
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 11-11-2008, 08:18 PM
  2. [SOLVED] Can't figure out what's wrong
    By roach_van in forum New To Java
    Replies: 10
    Last Post: 09-05-2008, 07:09 AM
  3. Urgent small code
    By karingulanagaraj in forum New To Java
    Replies: 7
    Last Post: 08-11-2008, 04:11 AM
  4. Replies: 2
    Last Post: 07-11-2008, 09:41 AM
  5. small error
    By ayoood in forum New To Java
    Replies: 23
    Last Post: 05-27-2008, 12:18 PM

Tags for this Thread

Posting Permissions

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