0 votes
272 views
in Java by
How will you print 20 random numbers in sorted order in java 8?

1 Answer

0 votes
by (2k points)
See the following running code to print 20 random numbers in sorted order:-

package com.java8.array;

import java.util.Random;

public class PrintTwentyRandomSortedNumbers {

    public static void main(String[] args) {
        Random random = new Random();
        random.ints().limit(20).sorted().forEach(System.out::println);
    }

}

Output:-
-1942875816
-1670507231
-1649047628
-1627087425
-1370767116
-745912496
-705292022
-701066452
-426232568
-123472729
75356103
117632358
457413236
935072541
1082865285
1294473712
1510067592
1804496303
1955022201
2063906205

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...