Guest User

Untitled

a guest
Mar 18th, 2019
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Ex7_19 {
  2. public static void isSorted(int[] list) {
  3. String s = "The list is sorted";
  4. String nS = "The list is not sorted.";
  5. System.out.print("The list has ");
  6. System.out.print(list.length);
  7. System.out.print(" integers ");
  8. for (int i = 0; i < list.length; i++) {
  9. System.out.print(list[i] + " ");
  10. }
  11.  
  12. for (int i = 0; i < (list.length - 1); i++) {
  13. if (list[i] > list[i + 1]) {
  14. return nS;
  15. }
  16. }
  17. return s;
  18. }
  19.  
  20. public static void main(String[] args) {
  21. System.out.println("#1");
  22. isSorted(new int[]{4,7, 19, 21, 44, 98, 101});
  23.  
  24. System.out.println("n#2");
  25. isSorted(new int[]{4,7, 54, 15, 19, 21, 44, 98, 101});
  26.  
  27. System.out.println("n#3");
  28. isSorted(new int[]{-2, 0, 3});
  29. }
  30. }
RAW Paste Data