title: Type mismatch: cannot convert from String to int
body: <p>I'm trying to write a Java code for my java class, and I'm getting the following error message when I run the code:</p>
  
  <pre><code>"Type mismatch: cannot convert from String to int;"
  </code></pre>
  
  <p>Here is the assignment:</p>
  
  <pre><code>"Write a program that reads in a single digit number from the keyboard into an
  integer variable. Your program will then print the number spelled out. If the user
  types in a number that is more than one digit, your program must print an error
  message. If the user types in a negative number, your program should print the word
  "negative" before the digit spelled out."
  </code></pre>
  
  <p>This is what I have so far:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class ReadsNumber{
  
      public static void main(String[] args){
  
          String[] a = new String[10];
  
           a[0] = "Zero";
           a[1] = "One";
           a[2] = "Two";
           a[3] = "Three";
           a[4] = "Four";
           a[5] = "Five";
           a[6] = "Six";
           a[7] = "Seven";
           a[8] = "Eight";
           a[9] = "Nine";
  
           Scanner inputStream = new Scanner(System.in);  
           int integer;
  
           while(true){
               System.out.println("Input an integer: ");
               integer = inputStream.next();
               if (integer &lt; 0)
                   System.out.println("negative");
               else if (integer &gt; 9)
                   System.out.println("error");
               else 
                   System.out.println(a[integer]);
           }
  
       }
  }
  </code></pre>