Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

switch and case

Posted on 2005-04-12
5
Medium Priority
?
244 Views
Last Modified: 2010-03-31
I want to make a list of options and after execution of each option I choose, I want to return to the list.
Here is my code:
      public static void main(String args[]){
          System.out.println("1. execute some method1");
          System.out.println("2. execute some method2");
          System.out.println("3. do method 3");
          System.out.println("4. Exit");
          System.out.println("Choose :");
 
          switch(izbira){
 
                case 1:      najvecjeI ();
                    break;
 
                case 2:      sinMax (tabela);
                     break;

                case 3:      Stoparica.start();
                      sinMax ();
                      break
 
                case 4:      System.exit(0);
                         break;
            default: main(args);
                      }
      }

after execution of each and every option I choose program stops ( because of break; ). What should I do that after execution of each option program will not break, but it will return to the begining?
0
Comment
Question by:tomaz108
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
VolatileVoid earned 432 total points
ID: 13763166
while (true) {
          System.out.println("1. execute some method1");
          System.out.println("2. execute some method2");
          System.out.println("3. do method 3");
          System.out.println("4. Exit");
          System.out.println("Choose :");
 
          switch(izbira){
 
               case 1:     najvecjeI ();
                  break;
 
               case 2:     sinMax (tabela);
                   break;

               case 3:     Stoparica.start();
                    sinMax ();
                    break
 
               case 4:     System.exit(0);
                        break;
            default: main(args);
                    }
}
0
 
LVL 1

Expert Comment

by:VolatileVoid
ID: 13763275
BTW, the default label shouldn't call main recursively... just have the default print out something like
System.out.println ("Invalid options selected!");
break;

Also, make sure you read in your variable (izbira) after you print out choose. I don't see any input statements there.
0
 

Author Comment

by:tomaz108
ID: 13763760
VolatileVoid
Could You please tell me how can I clear screen?
0
 
LVL 1

Expert Comment

by:VolatileVoid
ID: 13764731
I don't know if there's a non-system specific way of doing it...
If you're using Windows you could always do Runtime.getRuntime ().exec ("cls");
If you're using Linux you could do: Runtime.getRuntime ().exec ("clear");

But this isn't ideal. I know someone posted a few days ago about writing a method in C and using JNI to call it...
0
 

Author Comment

by:tomaz108
ID: 13765734
thanx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question