Results 1 to 3 of 3
- 11-23-2011, 06:06 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
Returning a value instead of false for a boolean
I would appreciate if anyone could help me with what seems to be a very simple question but i cannot get it to work. I have the following method:
public boolean search (int parameter)
{
for (int i = 0; i < intArray.length; i++)
{
if (parameter >= 0 && parameter <= i){
return true;
}
}
return false;
}
However instead of returning false i would like to return -1. Java does not compile as it expects a boolean. I know this is a basic question but can anyone please help.
- 11-23-2011, 06:10 AM #2
Re: Returning a value instead of false for a boolean
In that case you will need to change the return type of the method to int and have both return statements changed. You CANNOT have a method return two different types: true or -1.
- 11-23-2011, 11:33 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Boolean.True and Boolean.False, why do some people use these?
By Pojahn_M in forum New To JavaReplies: 3Last Post: 09-13-2011, 12:01 AM -
boolean error help when no boolean is given
By drewtrcy in forum New To JavaReplies: 18Last Post: 05-05-2011, 09:04 AM -
Set TexField to false
By globo in forum New To JavaReplies: 3Last Post: 11-18-2010, 08:46 PM -
can't get setVisible(false) to work
By alexander.s in forum AWT / SwingReplies: 0Last Post: 04-27-2010, 08:33 PM -
swirling becomes false,why?
By arefeh in forum New To JavaReplies: 2Last Post: 01-18-2010, 06:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks