In Java, is it possible to have a switch statement within a method, and return the case value? -


i working on simple black jack simulator (just beginning learn java) , have confusion how can return value method. possible return entirety of individual case method every time method run?

public static int player = 0; static random random = new random();  public static int randomcard = (random.nextint(13) + 1);   public static void yourcard() { //this need change return type            switch (randomcard) {             case 1:                  system.out.println("your card ace!");                 player += randomcard;                           //how return within case when method called                  system.out.println("your hand is:" + player);              case 2:             case 3:             case 4:             case 5:             case 6:             case 7:             case 8:             case 9:             case 10:                  system.out.println("your card " + randomcard + "!");                 player += randomcard;                 system.out.println("your hand is:" + player);              case 11:                  system.out.println("your card jack!");                 player += randomcard;                 //etc queen , king (will set value 10 these 3)  } 

you can use break when successful condition..and can assign method local variable before using break in case block. return whatsoever value outside switch block, want have stored in variable.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -