Open mohammadfahimkhan opened 11 months ago
package org.Practice.Array;
public class ArrayAssendingOrder { public static void main(String[] args) { int[] x = {100, 35, 74, 98, 86, 55, 14}; System.out.print("Original Array: "); for (int m = 0; m < x.length; m++) System.out.print(x[m] + " "); int temp = 0; for (int i=0; i<x.length; i++) { for (int j= i+1; j<x.length; j++) { if (x[i] > x[j]) { temp = x[i]; x[i] = x[j]; x[j] = temp; }
}
}
System.out.print("\nSorted Array: ");
for(int n = 0; n < x.length; n++)
System.out.print(x[n] + " ");
}
}
using the advance concept means stream(), You can do it like following. package org.question;
import java.util.Arrays;
public class AscendingOrderExample { public static void main(String[] args) { int[] number={10,20,7,-8,23,45,5,4}; Arrays.stream(number).sequential().sorted().forEach(n-> System.out.println(n)); } } -- Output -8 4 5 7 10 20 23 45
Question from session 'Class05_02'