title: Java Multiline Input
body: <p>I am trying to solve an online programming problem (Here it is: <a href="http://acm.timus.ru/problem.aspx?space=1&amp;num=1002" rel="nofollow">http://acm.timus.ru/problem.aspx?space=1&amp;num=1002</a>).  <br /> However, whenever i try the first input data as:<br /></p>
  
  <pre>
  7325189087        (a call number to decipher)
  20                (total number of words to input)
  ...               (input here Words up to 20 lines)
  </pre>
  
  <p>The Java console doesn't respond/hangs after the 20th line. Can anyone help me point where the error is occurring? I tried both Scanner and BufferedReader, as well as on Windows command prompt and JCreator's command line, but to no avail.
  <br/>
  Here's the code:</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  class PhoneNumbers {
  
      static List&lt;String&gt; cmb = new ArrayList&lt;String&gt;();
      static List&lt;String&gt; indices = new ArrayList&lt;String&gt;();
      static List&lt;String&gt; outputs = new ArrayList&lt;String&gt;();
  
      public static void main(String[] args) throws IOException{
          //BufferedReader in = new BufferedReader(new InputStreamReader((System.in)));
          Scanner in = new Scanner(new BufferedInputStream(System.in));
          String inp = "";
          while(true) {
              System.out.print(" ");
              inp = in.nextLine();
              if(inp.equals("-1")) break;
              System.out.print(" ");
              int loops = Integer.parseInt(in.nextLine());
              //String[] words = new String[loops];
              List&lt;String&gt; words = new ArrayList&lt;String&gt;();
              for(int i = 0; i &lt; loops; i++){
                  System.out.print(" ");
                  words.add(in.nextLine());       //Error occurs here. if loop is 20 line or more.
              }
              String nums = "";
              for(int i = 0; i &lt; words.size(); i++)
                  nums += i;
              Combi("",nums,words,inp.length());
              boolean isfound = false;
              String ind = "";
              int len = 100;
              for(int i = 0; i &lt; cmb.size(); i++){
                  String result = "";
                  for(int i2 = 0; i2 &lt; cmb.get(i).length(); i2++) {   
                      result += getVal((cmb.get(i).charAt(i2) + "").toLowerCase());
                  }
                  if(inp.equals(result)) {
                      isfound = true;
                      int len2 = indices.get(i).length();
                      if(len2 &lt; len){
                          len = len2;
                          ind = indices.get(i);
                      }
                  }
              }
              if(isfound){
                  String out = "";
                  for(int i = 0; i &lt; ind.length(); i++) {
                      int x = Integer.parseInt(ind.charAt(i) + "");
                      out += words.get(x);
                      if(i &lt; ind.length() - 1)
                          out += " ";
                  }
                  outputs.add(out);
              }
              else
                  outputs.add("No solution.");
              cmb.clear();
              indices.clear();
          }
  
          cmb.clear();
          indices.clear();
          for(int i = 0; i &lt; outputs.size(); i++)
              System.out.println(outputs.get(i));
      }
  
      public static void Combi(String pre, String s, List&lt;String&gt; col, int len) {
          if(!pre.equals("")){
              String nval = "";
              for(int i = 0; i &lt; pre.length(); i++){
                  nval += col.get(Integer.parseInt(pre.charAt(i) + ""));
              }
              if(nval.length() == len){
                  cmb.add(nval);
                  indices.add(pre);
                  Perm("",pre,col,len);
              }
          }
          for(int i = 0; i &lt; s.length(); i++)
              Combi(pre + s.charAt(i), s.substring(i + 1),col,len);
      }
  
      public static void Perm(String pre, String s, List&lt;String&gt; col, int len) {
          int n = s.length();
          if(n == 0){
              String nval = "";
              for(int i = 0; i &lt; pre.length(); i++){
                  nval += col.get(Integer.parseInt(pre.charAt(i) + ""));
              }
              if(cmb.contains(nval) == false){
                  cmb.add(nval);
                  indices.add(pre);
              }
          } else{
              for(int i = 0; i &lt; n; i++)
                  Perm(pre + s.charAt(i), s.substring(0,i) + s.substring(i + 1, n),col,len);
          }
      }
  
      public static int getVal(String ltr) {
          if (ltr.equals("i") || ltr.equals("j"))
              return 1;
          if (ltr.equals("a") || ltr.equals("b") || ltr.equals("c"))
              return 2;
          if (ltr.equals("d") || ltr.equals("e") ||ltr.equals("f"))
              return 3;
          if(ltr.equals("g") || ltr.equals("h"))
              return 4;
          if (ltr.equals("k") || ltr.equals("l"))
              return 5;
          if (ltr.equals("m") || ltr.equals("n"))
              return 6;
          if (ltr.equals("p") || ltr.equals("r") || ltr.equals("s"))
              return 7;
          if (ltr.equals("t") || ltr.equals("u") || ltr.equals("v"))
              return 8;
          if (ltr.equals("w") || ltr.equals("x") || ltr.equals("y"))
              return 9;
          if (ltr.equals("o") || ltr.equals("q") || ltr.equals("z"))
              return 0;
          return -1;
      }
  }
  </code></pre>
  
  <p>P.S. - I apologize if my codes is still not that efficient. I'm still practicing :D
       <br />- There are some System.Print(" ") because JCreator's console is quite bugged handling inputs without print something first.
  <br /> - I do not ask for helps about this problem. I just ask why Java hangs on the 20th line without any reason.</p>
  
  <p>Thank you in advance for the help.</p>