title: Why won't my string hold spaces?
body: <pre><code>import java.util.Scanner;
  
  public class TestEditor {
      public static void main(String[] args){
          String input;
          char[] words = new char[100];
          int choice=0;
          int start=0;
          int end=0;
          LineEditor myEditor = new LineEditor();
          LineEditor myEditor2 = new LineEditor();
          String input2 = null;
          System.out.println("+++++++ LineEditor starts... +++++++\n");
          System.out.println("* Write the text you want (maximum length: 100): ");
          Scanner in = new Scanner(System.in);
          input = in.next();
          while(input.length()&gt;100){
              System.out.println("* Operation failed: You exceeded the maximum length.");
              System.out.println("* Write the text you want (maximum length: 100): ");
              input = in.next();
              System.out.println("\n");
          }
  
          System.out.println("--------------------------------------\n");
          do{
              System.out.println("*Choose the menu:\n1. Insert\n2. Delete\n3. Replace\n4. Quit");
              choice=in.nextInt();
              System.out.println("\n");
              if(choice==1){
                  System.out.println("* Enter the starting position:");
                  start = in.nextInt();
                  System.out.println("* Enter the text you want to replace:");
                  input2=in.next();
                  myEditor.insert(input, start, input2);
              }
              if(choice ==2){
                  System.out.println("* Enter the starting and ending position for deletion.");
                  start=in.nextInt();
                  end=in.nextInt();
                  myEditor.delete_text(input, start,end);
              }
              if(choice==3){
                  System.out.println("* Enter the starting and ending position for insertion.");
                  start=in.nextInt();
                  end=in.nextInt();
                  System.out.println("* Enter the text you want to replace:");
                  input2=in.next();
                  myEditor.replace(input, input2, start, end);
              }
          }while(choice !=4);
          System.out.println("Good Bye!");
      }
      }
  
  
      public class LineEditor {
      private static char [] text;
      private static char [] text2;
  
  
      public LineEditor(){
          text=new char[100];
          text2=new char[100];
      }
  
      public void insert(String input, int start, String input2){
          start = start-1;
          int j=0;
          for(int i=0;i&lt;input.length();i++){
              text[i]=input.charAt(i);
          }
          for(int i=0; i&lt;input2.length();i++){
              text2[i]=input2.charAt(i);
          }
          for(int i=start; i&lt;input.length();i++){
              text[i]=text[i+start];
          }
          for(int i=start; i&lt;input.length();i++){
              text[i]=text2[j];
              j++;
          }
          for(int i=0; i&lt;text.length;i++){
              System.out.print(text[i]);
          }
  
      }
      public void delete_text(String input, int start, int end){
          for(int i=0;i&lt;input.length();i++){
              text[i]=input.charAt(i);
          }
          start=start-1;
          int num = end-start;
          for(int i=start; i&lt;end;i++){
              text[i]=text[i+num];
          }
          for(int i=end;i&lt;text.length;i++){
              if((i+end)&lt;100){
                  text[i]=text[i+end];
              }else{
                  text[i]=text[i-end];
              }
          }
          for(int i=0; i&lt;text.length;i++){
              System.out.print(text[i]);
          }
      }
      public void replace(String input, String input2, int start, int end){
          start = start-1;
          int j=0;
          for(int i=0;i&lt;input.length();i++){
              text[i]=input.charAt(i);
          }
          for(int i=0; i&lt;input2.length();i++){
              text2[i]=input2.charAt(i);
          }
          for(int i=start; i&lt;input.length();i++){
              text[i]=text[i+start];
          }
          for(int i=start; i&lt;input.length();i++){
              text[i]=text2[j];
              j++;
          }
          for(int i=0; i&lt;text.length;i++){
              System.out.print(text[i]);
          }
  
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>Exception in thread "main" java.util.InputMismatchException
  at java.util.Scanner.throwFor(Unknown Source)
  at java.util.Scanner.next(Unknown Source)
  at java.util.Scanner.nextInt(Unknown Source)
  at java.util.Scanner.nextInt(Unknown Source)
  at TestEditor.main(TestEditor.java:29)
  </code></pre>
  
  <p>So those are my two classes and I keep getting this error when I put a space in my initial input. The error doesn't even happen when I transfer it to an array. Can someone shed some light? Also here is a <a href="https://wiki.ittc.ku.edu/ittc/EECS168%3aHomework4" rel="nofollow">link for the exact prompt</a> if you would like to look at it.</p>