XtraStudy Header

Blogs ➤ Articles

Java 8 Program to Print ten random numbers using forEach

Tags : #Java8, #Coding, #JavaProgram, #Java   Author : Admin
Updated : 14-Feb-2023 👁 402


Java 8 Program to Print ten random numbers using forEachJava 8 Program to Print ten random numbers using forEach

Below is the program to generate 10 random number using forEach.
Here we are using Random class to generate Random number.


import java.util.Random;
public class Main {    
  public static void main(String[] args) {    
    Random random = new Random();
    random.ints().limit(10).forEach(System.out::println);
  }    
}  


Output


-1268703499
1402039482
-447617610
1637994480
323203484
684637852
478114337
-138286191
-1243111432
733650229


Comments
Comments (0)


App Link

xtrastudy android app
Others

Earn While You Learn
FAQ

Register Now

© 2022 Company, Inc. All rights reserved.