title: Code efficiency. Effective way of using loops
body: <p>I am building a framework for a web application and would like to perform certain simple tasks like input retrieval and displaying them. Below is have the code, I feel the code can be improved and isn't efficient. Note:All three methods have the same implementation.</p>
  
  <p>The Switch needs to be implemented twice one within the IF loop and the other for general case. </p>
  
  <pre><code>    public class selector8
  {
        public static void main (String [] args){
  
      selector8 obj1 = new selector8();
      Scanner inputString = new Scanner (System.in);
      Scanner inputYN = new Scanner (System.in);
      String input, A,B,C;
  
      System.out.println("Choose. A || B || C || X to exit");
      input = inputString.nextLine();
      char contLoop1 = 'y';
      do{
          if(input.equalsIgnoreCase("y")) {
              input = "";
              System.out.println("Choose. A || B || C || X to exit");
              input = inputString.nextLine();
              switch (input){
  
              case("a"):
                  obj1.startMethod1(input);
                  break;
  
              case("b"):
                  obj1.startMethod2(input);
                  break;
  
              case("c"):
                  obj1.startMethod3(input);
                  break;
  
              case("x"):
                  System.out.println("Goodbye");
                  break;
  
              case ("n"):
                  System.out.println("See ya");
                  break;
  
              default:
                      System.out.println("Invalid argument. Try again");
                      break;
  
                  }
          } else
          switch (input){
  
          case("a"):
              obj1.startMethod1(input);
              break;
  
          case("b"):
              obj1.startMethod2(input);
              break;
  
          case("c"):
              obj1.startMethod3(input);
              break;
  
          case("x"):
              System.out.println("Goodbye");
              break;
  
          case ("n"):
              System.out.println("See ya");
              break;
  
          default:
                  System.out.println("Invalid argument. Try again");
                  break;
  
              }
              System.out.println("Do want to try again " +"Y/N" );
              input = inputYN.nextLine(); 
              contLoop1 = input.charAt(0);
      }while(contLoop1 != 'n');
  }
  
  public void startMethod1(String A){
      String input;
  
      Scanner inputString = new Scanner (System.in);
      System.out.println("Enter a or b");
      input = inputString.nextLine();
  
      switch (input){
  
      case("a"):
          System.out.println("output parsed");
      break;
  
      case("b"):
          System.out.println("output parsed");
      break;
  
      default:
          System.out.println("Invalid argument");
      }
  }
  
  public void startMethod2(String B){
  
      String input;
      Scanner inputString = new Scanner (System.in);
      System.out.println("Enter a or b");
      input = inputString.nextLine();
      switch (input){
      case("a"):
          System.out.println("output parsed");
      break;
      case("b"):
          System.out.println("output parsed");
      break;
  
      default:
          System.out.println("Invalid argument");
          break;
      }
  }
  
  public void startMethod3(String C){
  
      String input;
      Scanner inputString = new Scanner (System.in);
      System.out.println("Enter a or b");
      input = inputString.nextLine();
      switch (input){
      case("a"):
          System.out.println("output parsed");
      break;
      case("b"):
          System.out.println("output parsed");
      break;
  
      default:
          System.out.println("Invalid argument");
      }
  }
  }
  </code></pre>
  
  <p>On a side note could you also tell me why can static classes be called without an object?</p>
  
  <pre><code>public class StaticImplementation{
  public static void main (String [] args){
  StaticImplementation obj1 = new StaticImplementation();
  obj1.stat(); //is invalid
  stat(); //is valid
  }
  static void stat(){
      System.out.println("Static class");
  }
  </code></pre>
  
  <p>Thanks a bunch. Have a good day! </p>