Find longest ascending number sequence in a string
<p>The program is supposed to give the longest ascending order.</p>

<p>So, for example, if I input "12134707" it should give output = 1347 however it's giving 12... which is definitely not the longest. what am I missing or doing wrong? </p>

<pre><code>import java.util.Scanner;        
public class Ascending
{

public static void main(String args[]){

    System.out.print("Enter a number = ");

    Scanner in = new Scanner(System.in);
    String n = in.nextLine();

    //print soluton
    System.out.println("output = " + itsAscending(n));
}

public static String itsAscending(String n) {
    int length = n.length(); 

    String maxlongest = "";


    for(int i = 1; i &lt; length; i++) {

        char first = n.charAt(i-1); 
        char second = n.charAt(i);      
        char next = n.charAt(i+1);
        int f = (int)(first - 48);      
        int s = (int)(second - 48);     
        int nx = (int)(next - 48);

        String longest = "";

        int max = 0;


        //test to find the ascending order
        if (f&lt;s){

            longest = longest + f;

            if(n.length()&gt;2){

                if(f&lt;s){
                    longest = longest + s;
                    length = longest.length();
                    i++;
                }
                else{
                    i++; 
                    continue;
                }
            }

            //test to find the longest string
            for (i=1; i&lt;length; i++){
                if (length &gt; max){
                    max = length;
                    maxlongest = longest;
                    return maxlongest;
                }
                else {
                    return maxlongest;
                }
            }
        }
    }
    return maxlongest;
 }
}
</code></pre>
