Results 1 to 4 of 4
Thread: Problem with Else if
- 04-02-2009, 07:48 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 11
- Rep Power
- 0
Problem with Else if
Hi guys! The following is a code I did, with if and else if statements. But I kept getting errors , saying that I can't have 'else' without an 'if' .
public void PirateExplore(Player p) {
double randomEventType = Math.random() * 100;
if (randomEventType =< 5.00 ) {
ItemResourceEventGenerator(p);
}
else if (randomEventType =< 12.50 ) {
Random rgen = new Random();
int type = rgen.nextInt(2);
if (type == 0) {
GoodEventGenerator(p);
} else {
BadEventGenerator(p);
}
}
else if (randomEventType =< 70.00 ) {
NothingEventGenerator(p);
}
Help! thanks!!!
- 04-02-2009, 08:01 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
This is wrong actually. Not a legal expression in Java.
You cannot do the comparison like this. It must be <=Java Code:if (randomEventType =< 5.00 ) {
- 04-02-2009, 08:02 AM #3
Member
- Join Date
- Sep 2008
- Posts
- 11
- Rep Power
- 0
Alright thanks!!
- 04-02-2009, 08:08 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
NP, if you have solved the problem please mark it as solved.


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks