Guys Im new to java - Trivial question

public boolean isBooked(int day,int time){

StringTokenizer tk = new StringTokenizer(bookings);

while (tk.hasMoreTokens()){

String str = tk.nextToken();

if (str.startsWith(day+"^"+time)){

return true;}

else{

return false;}

}

}

1 error found:

File: F:\UTM\csc108h\Test\Car.java [line: 63]

Error: missing return statement

[397 byte] By [salonaha] at [2007-10-2 4:45:58]
# 1
Which line is line 63?Kaj
kajbja at 2007-7-16 0:50:51 > top of Java-index,Java Essentials,Java Programming...
# 2
Oh, and please use code tags when you post code: http://forum.java.sun.com/help.jspa?sec=formattingKaj
kajbja at 2007-7-16 0:50:51 > top of Java-index,Java Essentials,Java Programming...
# 3
The problem is both of your return statements are inside the while loop.Your code doesn't make sense anyway. Inside the while loop you have an if/else statement which means the "loop" will only ever execut once anyway, so the while loop isn't even needed.
camickra at 2007-7-16 0:50:51 > top of Java-index,Java Essentials,Java Programming...
# 4
Suppose tk.hasMoreTokens() is false right off the bat. So it never even gets into the "while" loop at all. Then what will it return? That's basically what the compiler is complaining about.
warnerjaa at 2007-7-16 0:50:51 > top of Java-index,Java Essentials,Java Programming...
# 5

Thanks all - This finally works!

<code>public boolean isBooked(int day,int time){

StringTokenizer tk = new StringTokenizer(bookings);

while (tk.hasMoreTokens()){

String str = tk.nextToken();

if (str.startsWith(day+"^"+time)){

return true;

}

}

return false;

}

</code>

salonaha at 2007-7-16 0:50:51 > top of Java-index,Java Essentials,Java Programming...