Results 1 to 5 of 5
Thread: Break to certain class
- 10-19-2008, 10:32 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 2
- Rep Power
- 0
Break to certain class
say I have this:
in the first class, when someone chooses "q", the entire program stops which is good.Java Code:public void handleInput() { mainMenu(); String input=scanner.next(); while (!input.startsWith("q")) { if (input.startsWith("a")) { System.out.println("1"); } else if (input.startsWith("b")) System.out.println("2"); } else if (input.startsWith("q")) { break; } } } private void handleTrigInput() { trigMenu(); String input=scanner.next(); while (!input.startsWith("q")) { if (input.startsWith("a")) { System.out.println("1"); } else if (input.startsWith("q")) { break; } handleInput(); }
in the handleTrigInput class when "q" is selected it goes back to handleInput like it should, but then i cant quit out of the first menu.
what's wrong here? is there a simple way to break to another class?Last edited by Arez; 10-19-2008 at 10:39 PM.
- 10-19-2008, 11:40 PM #2
Code missing...
You need to post the rest of the code.
- What does the startsWith method do?
- What does the handleInput method do?
Something that you can do is use println() through out your code to follow flow and help you debug.
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 10-20-2008, 12:14 AM #3
A few comments:
The break statement is to exit a loop, not a class.
You don't exit a class, you exit a method.
"break to another class" doesn't make sense.
To exit from a method you can return.
- 10-20-2008, 02:02 AM #4
Member
- Join Date
- Jul 2008
- Posts
- 68
- Rep Power
- 0
Is it just me or does it look like you will never execute
inside of a while loop with the conditionJava Code:else if (input.startsWith("q")) { break; }
Java Code:while (!input.startsWith("q"))
- 10-20-2008, 04:13 AM #5
If this is not homework, and you want to really parse options and switches, I recommnd
JSAP: The Java Simple Argument Parser
Similar Threads
-
Break Clock
By BruenorBH in forum Advanced JavaReplies: 20Last Post: 09-12-2008, 05:27 AM -
Line break for textlayout
By Java Tip in forum java.awtReplies: 0Last Post: 06-25-2008, 10:32 AM -
How to use Break with a label
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:45 PM -
How to use Break
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:45 PM -
Line break in tool tip..how??
By sandor in forum AWT / SwingReplies: 1Last Post: 05-16-2007, 01:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks