shahnawazm786 / automation_weekly_batch_

Automation Batch Weekly Class 9.00 AM to 10:00 AM
1 stars 0 forks source link

Arrange in ascending order_11 #12

Open mohammadfahimkhan opened 11 months ago

mohammadfahimkhan commented 11 months ago

Question from session 'Class05_02'

Anwar1501 commented 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] + " ");
}

}

shahnawazm786 commented 11 months ago

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