//Write a Java program to find whether an array is sorted or not

 



import java.util.Scanner;
public class CDM_P6 {
public static void main(String[] args) {
boolean sorted = true;
int []array = {56,90,65,89,34,29,98};
for(int i =0; i<array.length-1;i++){
if(array[i]>array[i+1]){
sorted =
false;
break;
}
}
if(sorted){
System.
out.println("Array is sorted");
}
else{
System.
out.println("Array is not sorted");
}

}
}

//output
Array is not sorted Process finished with exit code 0



Post a Comment

0 Comments