“Sortuj Java.” Kod odpowiedzi

Sortuj Java.

import java.util.Arrays;
 
class GFG {
    public static void main(String args[])
    {
        int[] arr = { 5, -2, 23, 7, 87, -42, 509 };
        System.out.println("The original array is: ");
        for (int num : arr) {
            System.out.print(num + " ");
        }
        Arrays.sort(arr);
        System.out.println("\nThe sorted array is: ");
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}
Bad Batfish

Java sort int tablic

// an array of ints
int[] arr = {1, 2, 3, 4, 5, 6};

// an array of reverse sorted ints
int[] arrDesc = Arrays.stream(arr).boxed()
    .sorted(Collections.reverseOrder())
    .mapToInt(Integer::intValue)
    .toArray();

System.out.println(Arrays.toString(arrDesc)); // outputs [6, 5, 4, 3, 2, 1]
Difficult Donkey

Odpowiedzi podobne do “Sortuj Java.”

Pytania podobne do “Sortuj Java.”

Więcej pokrewnych odpowiedzi na “Sortuj Java.” w Java

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu