title: Assigning multiple variables in one string - Java
body: <p>How do I assign values to multiple varibles from one line of string. For example.</p>
  
  <pre><code>String time = sc.next(); // the amount of time to delay from shutdown
  String timeframe = sc.next(); // time frame : seconds, minutes, ect
  </code></pre>
  
  <p>If this would be for a shutdown code, and the user enters "10 mins", how would I assign the variable 10 to an integer (of course after I parse it), and use the time frame (along with some math) to create the delay to the shutdown.</p>
  
  <p>The end goal, for this part of the program, is to give the user the ability to enter one clean command "shutdown 10 mins", and to have windows schedule a shutdown 10 minutes from now.</p>
  
  <p>Currently, the user would have to do : "shutdown"  [ENTER] "10" [ENTER] "mins" [ENTER].</p>
  
  <p>The rest of the program is fine, only this gives me the problem of irregularity.</p>
  
  <p>Complete code for class :</p>
  
  <pre><code>public void Start() {
          Scanner sc = new Scanner(System.in);
          int xtime = 0;
          boolean goodTime = false, goodTimeFrame = false;
  
          String time = sc.next();
          String timeframe = sc.next();
  
          try {
              xtime = Integer.parseInt(time);
  
              if(xtime&lt;0) { System.out.println("time cannot be less than 0..."); }
              else if(xtime&gt;=0) { goodTime = true; }
          } catch(Exception e){ System.out.println("invalid input..."); }
  
          try {
              switch(timeframe.toLowerCase()) {
                  case "secs":
                      xtime = xtime*1000;
                      goodTimeFrame = true;
                      break;
                  case "mins":
                      xtime = xtime*60000;
                      goodTimeFrame = true;
                      break;
                  case "hrs":
                      xtime = xtime*3600000;
                      goodTimeFrame = true;
                      break;
                  default:
                      System.out.println("invalid timeframe, use: secs, mins, or hrs...");
                      break;
              }
          } catch(Exception e){ System.out.println("cannot convert to valid time..."); }
  
          if(goodTime &amp;&amp; goodTimeFrame) {
              try {
                  Runtime.getRuntime().exec("Elevate.exe shutdown -s -t "+xtime);
              } catch(Exception e){ System.out.println("error ordering shutdown command..."); }
          }
          else { System.out.println("syntex example : shutdown time timeframe"
                                                   + "\nshutdown 10 mins"); }
      }
  </code></pre>