title: Passing a value from one case to another in switch statement
body: <p>So here is a sample code :</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Test {
  
  public static void main(String[] args) {
      System.out.println("Please type in a number");
      Scanner in = new Scanner(System.in);
      switch (in.nextInt()){
          case 1:
              save(in);
              break;
          case 2:
              System.out.println(value);
              break;
          default:
              System.out.println("Default case");
              break;
      }               
      in.close();
  }
  
  public static String save(Scanner in){
  System.out.println("Type in a word");
  String value = in.next();
  return value;
  }
  }
  </code></pre>
  
  <p>In this particular situation all I am trying to do here is to have access to the <code>value</code> that was stored in case 1.</p>