title: Why wouldn't the code work in the for loop?
body: <p>Homework problem got the first 4 questions got stuck on this last one. If the user inputted hello as the string and 3 as the integer it's supposed to print "helheh" when I try it prints "helhehehehehe"</p>
  
  <p>Question:Write a program that reads a string and an integer, n, from the user. Output a string made of the first n characters of the string, followed by the first n-1 characters of the string, and so on. You may assume that n is between 0 and the length of the string, inclusive.</p>
  
  <p>I tried having it add to the string with i-1 in the substring section but that didn't work.</p>
  
  <pre><code> System.out.println("Please input a string: ");
   string = in.next();
  
   System.out.println("Please input an integer: ");
   n = in.nextInt();
  
   int lenstring = string.length();
  
   String tring = string.substring(0,n);
   for(int i = lenstring; i&gt;0; i--)
   {
       con += string.substring(0,n-1);
   }
  System.out.println(tring+con);
  </code></pre>