Results 1 to 13 of 13
Thread: continue outside of loop...
- 05-03-2012, 10:23 AM #1
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
continue outside of loop...
Java Code:while(!Player.isDead && !Enemy.isDead); { System.out.println("Your current weapon is a " + Player.heldItem.Name); System.out.println("Choose an action:"); System.out.println("A. Attack"); System.out.println("B. Block"); System.out.println("C. Choose Weapon"); System.out.println("D. Evade"); Player.startBattle(); Enemy.startBattle(); String choice = input.readLine(); if(choice == "a") { Player.isAttacking = true; Player.Attack(); Player.isIdle = false; } else if(choice == "b") { Player.isBlocking = true; Player.isIdle = true; } else if(choice == "d") { Player.isEvading = true; Player.Evaded = (carl.nextInt(4) != 0); Player.isIdle = true; } else if(choice == "c") { System.out.println("Choose a Weapon"); System.out.println("A. Sword"); System.out.println("B. Club"); System.out.println("C. Staff"); String choice2 = input.readLine(); if(choice2 == "a") { Player.heldItem = BaseWeapon.Sword; } else if(choice2 == "b") { Player.heldItem = BaseWeapon.Club; } else if(choice2 == "c") { Player.heldItem = BaseWeapon.Staff; } else { System.out.println("Incorrect input"); } continue; } else { System.out.println("Incorrect input"); continue; } Enemy.whatToDo(); Player.endOfRound(); Enemy.endOfRound(); }
- 05-03-2012, 10:31 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 05-03-2012, 10:33 AM #3
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
oops... thanks heaps man!
EDIT: now is says 'unreported exception java.io.IOException; must be caught or declared to be thrown' on line 25 and line 49, the lines i declare the strings onLast edited by J-max04; 05-03-2012 at 10:46 AM.
- 05-03-2012, 10:58 AM #4
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
fixed that, need help with a runtime error:
Exception in thread "main" java.lang.NoSuchMethodError: mainLast edited by J-max04; 05-03-2012 at 11:04 AM.
- 05-03-2012, 11:39 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: continue outside of loop...
You need a main() method in the class you are attempting to execute.
Please do not ask for code as refusal often offends.
** This space for rent **
- 05-03-2012, 11:41 AM #6
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
the while loop is in the main method
Java Code:void main(String args[])
- 05-03-2012, 12:07 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: continue outside of loop...
Have you read a tutorials on the basics of Java? You must've missed the fact that the main( ... ) method has to be static.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 05-03-2012, 12:33 PM #8
Re: continue outside of loop...
... and public
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 05-03-2012, 01:05 PM #9
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
I KNOW THE BASICS OF JAVA! i had it static... and public before, and in my attempts to fix it i changed it to what it is!
EDIT; heres some irony, when i change it back it suddenly works!(i must have a messed up IDE)
- 05-03-2012, 02:11 PM #10
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
Now whenever i input it says "Incorrect input"...
- 05-03-2012, 02:15 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: continue outside of loop...
Don't sompare Strings using '==', use equals() instead.
Please do not ask for code as refusal often offends.
** This space for rent **
- 05-04-2012, 01:58 AM #12
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
whats the syntax for that? equals(String, String)?
- 05-04-2012, 02:48 AM #13
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Similar Threads
-
Interrupt loop without break or continue
By mwr1976 in forum New To JavaReplies: 2Last Post: 10-12-2011, 04:43 AM -
use Continue with label
By er1c550n20 in forum New To JavaReplies: 2Last Post: 04-04-2010, 02:24 PM -
Continue or not?
By kliane in forum New To JavaReplies: 3Last Post: 01-19-2010, 03:42 PM -
press any key to continue
By dotnet007 in forum New To JavaReplies: 3Last Post: 05-11-2008, 06:19 AM -
How to use Continue
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 08:46 PM
Bookmarks