Home > Back-end >  A switch statement
A switch statement

Time:09-19

I am novice, found a video self-study Java at first, but video images in a switch statement a little don't understand, is the case then print statements, but the back and a return return values, the two behind with a, don't know how to call this method, can let the two display of non-interference in each other, because the original video courses are missing, not the next set, so the card, want to trouble you give me a solution to reassure  ?

CodePudding user response:

What do you mean? Is the premise of without changing chu method also output return value to choose?
Where you need to call methods (such as the main method in) add the following code
Int choose=new Persion (), chu ();//call the method to obtain the return value
System. The out. Printf (" your choice is: % d ", choose);//print the return value

CodePudding user response:

Look at this method, should be, you are in somewhere else, such as the main method, the use of the Person. Chu calls it, to run the program later, will let you input a number, the console input, after entering the switch cycle, judgment, for example, if the input is 1 then print, you punch: stone, then break the end loop, executed, down to return after the end of this method, the return of the return value is choose, is you to enter the Numbers 1 to your caller, you can use an int I=Person. Chu; To receive, then you can use I to do any other code operations, should be able to understand it

CodePudding user response:

Well, forget, look at the upstairs bosses, call this method when need to new, int choose=new Person (). Chu (); So to invoke
  • Related