title: IndexOf and SIN
body: <p>I am building a calculator but if i do not have anything to the left of "sin" i do not get an output. But if i put numbers before "sin" it will perform the operation and give me the sin of the numbers to the right. I want it to be able give you the sin of a number even if put in as.... "sin43"</p>
  
  <pre><code>    import java.util.Scanner;
  
      public class InputScanner_operations {
      public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      String str;
  
      System.out.println("Input your equation");
  
      str = input.nextLine();
  
      int X = str.indexOf("X");
      int x = str.indexOf("x");
      int div = str.indexOf("/");
      int plu = str.indexOf("+");
      int sub = str.indexOf("-");
      int sin = str.indexOf("s");
  
      int type = 0;
  
      if (X != -1)
          type = 1;
      else if (x != -1)
          type = 2;
      else if (div != -1)
          type = 3;
      else if (plu != -1)
          type = 4;
      else if (sub != -1)
          type = 5;
      else if (sin != -1)
          type = 6;
      else
          type = 0;
  
      switch (type) {
  
      case 1: {
          int pos = str.indexOf("X");
          for (int i = 1; i &lt;= pos; i++) {
  
              String upToNCharacters = str.substring(0,
                      Math.min(str.length(), i));
              String downToNCharacters = str.substring(pos + 1,
                      Math.max(str.length(), i));
  
              if (i == pos) {
  
                  Double left = Double.parseDouble(upToNCharacters);
                  Double right = Double.parseDouble(downToNCharacters);
                  System.out.println(left * right);
              }
          }
      }
          break;
      case 2: {
          int pos = str.indexOf("x");
          for (int i = 1; i &lt;= pos; i++) {
  
              String upToNCharacters = str.substring(0,
                      Math.min(str.length(), i));
              String downToNCharacters = str.substring(pos + 1,
                      Math.max(str.length(), i));
  
              if (i == pos) {
  
                  Double left = Double.parseDouble(upToNCharacters);
                  Double right = Double.parseDouble(downToNCharacters);
                  System.out.println(left * right);
              }
          }
      }
          break;
      case 3: {
          int pos = str.indexOf("/");
          for (int i = 1; i &lt;= pos; i++) {
  
              String upToNCharacters = str.substring(0,
                      Math.min(str.length(), i));
              String downToNCharacters = str.substring(pos + 1,
                      Math.max(str.length(), i));
  
              if (i == pos) {
  
                  Double left = Double.parseDouble(upToNCharacters);
                  Double right = Double.parseDouble(downToNCharacters);
                  System.out.println(left / right);
              }
          }
      }
  
          break;
      case 4: {
          int pos = str.indexOf("+");
          for (int i = 1; i &lt;= pos; i++) {
  
              String upToNCharacters = str.substring(0,
                      Math.min(str.length(), i));
              String downToNCharacters = str.substring(pos + 1,
                      Math.max(str.length(), i));
  
              if (i == pos) {
  
                  Double left = Double.parseDouble(upToNCharacters);
                  Double right = Double.parseDouble(downToNCharacters);
                  System.out.println(left + right);
              }
          }
      }
          break;
      case 5: {
          int pos = str.indexOf("-");
          for (int i = 1; i &lt;= pos; i++) {
  
              String upToNCharacters = str.substring(0,
                      Math.min(str.length(), i));
              String downToNCharacters = str.substring(pos + 1,
                      Math.max(str.length(), i));
  
              if (i == pos) {
  
                  Double left = Double.parseDouble(upToNCharacters);
                  Double right = Double.parseDouble(downToNCharacters);
                  System.out.println(left - right);
              }
          }
      }
      case 6: {
          int pos = str.indexOf("s");
          for (int i = 1; i &lt;= pos; i++) {
              String upToNCharacters = str.substring(0,
                      Math.min(str.length(), i));
              String downToNCharacters = str.substring(pos + 3,
                      Math.max(str.length(), i));
  
              if (i == pos) {
  
              @SuppressWarnings("unused")
              Double left = Double.parseDouble(upToNCharacters);
              Double right = Double.parseDouble(downToNCharacters);
              System.out.println(Math.sin(right));
              }
          }
      }
          break;
      default:
          System.out.println("Please check your formatting");
  
          }
      }
  }
  </code></pre>