String processing using scanner
<p>Question: Write a method called wordWrap that accepts a Scanner representing an input file as its parameter and outputs each line of the file to the console, word-wrapping all lines that are longer than 60 characters. For example, if a line contains 112 characters, the method should replace it with two lines: one containing the first 60 characters and another containing the final 52 characters. A line containing 217 characters should be wrapped into four lines: three of length 60 and a final line of length 37.</p>

<p><strong>My code:</strong></p>

<pre><code>public void wordWrap(Scanner input) {

    while(input.hasNextLine()){
        String line=input.nextLine();
        Scanner scan=new Scanner(line);
        if(scan.hasNext()){
            superOuter:
            while(line.length()&gt;0){

                for(int i=0;i&lt;line.length();i++){
                    if( i&lt;60 &amp;&amp; line.length()&gt;59){
                        System.out.print(line.charAt(i));

                    }
                    //FINISH OFF LINE&lt;=60 characters here

                    else if(line.length()&lt;59){

                        for(int j=0;j&lt;line.length();j++){
                            System.out.print(line.charAt(j));

                        }
                        System.out.println();

                        break superOuter;
                    }
                    else{
                        System.out.println();

                        line=line.substring(i);

                        break ;
                    }


                }

            }
        }
        else{
            System.out.println();
        }

    }
}
</code></pre>

<p><em>Problem in the output:</em></p>

<p><strong>Expected output:</strong></p>

<pre>
Hello
How are you
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog
I am fine

Thank you
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog

This line is exactly sixty characters long; how interesting!

Goodbye
</pre>

<p><strong>Produced Output:</strong></p>

<pre>
Hello
How are you
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog
I am fine

Thank you
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog the quick brown 
fox jumps over the lazy dog

This line is exactly sixty characters long; how interesting!This line is exactly sixty characters long; how interesting!This line is exactly sixty characters long; how interesting!...
*** ERROR: excessive output on line 13
</pre>

<p><em>Where did i do wrong ????</em> </p>
