Results 1 to 5 of 5
  1. #1
    Arez is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default Break to certain class

    say I have this:

    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 first class, when someone chooses "q", the entire program stops which is good.

    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.

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default 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.
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,571
    Rep Power
    23

    Default

    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.

  4. #4
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    Is it just me or does it look like you will never execute

    Java Code:
     else if (input.startsWith("q"))
    			{
    				break;
    			}
    inside of a while loop with the condition

    Java Code:
    while (!input.startsWith("q"))

  5. #5
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    If this is not homework, and you want to really parse options and switches, I recommnd
    JSAP: The Java Simple Argument Parser

Similar Threads

  1. Break Clock
    By BruenorBH in forum Advanced Java
    Replies: 20
    Last Post: 09-12-2008, 05:27 AM
  2. Line break for textlayout
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 10:32 AM
  3. How to use Break with a label
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:45 PM
  4. How to use Break
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:45 PM
  5. Line break in tool tip..how??
    By sandor in forum AWT / Swing
    Replies: 1
    Last Post: 05-16-2007, 01:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •