I have a problem in execution of a java program which counts the longest sorted array but the result is always equal to initial value max = 1
, where can be the problem?
package longestsortedsquence;
public class Longestsortedsquence {
public static void main(String[] args) {
int[] arry={3,98,274,943,23,56,23,4};
System.out.print(longestsortedsequence(arry));
}
public static int longestsortedsequence(int[] arry){
if(arry==null){
return 0;
}
int max=1;
int len=1;
for(int i=0;i<arry.length-1;i++){
if(arry[i]<=arry[i+1]){
len=len++;
}
else{
len=1;
}
if(max<len){
max=len;
}
}
return max;
}
}