+ 6

Java

function for random value in java.is there any????

22nd Jan 2018, 11:05 AM
Shubh Mehrotra
Shubh Mehrotra - avatar
4 Réponses
+ 12
//import class package. import java.util.Random; //main(Start of program). //Creating a instance of class Random. Random rnd = new Random(); //Generate a number from 0 - 9. int number = rnd.nextInt(10); //Prints the value of the assigned interger. System.out.println(number);
22nd Jan 2018, 11:15 AM
D_Stark
D_Stark - avatar
+ 12
// main(Start of program) // Generate a number from 0 - 9 int number = Math.random() * 10; // Prints 'number' System.out.println(number); /* Although this is also an option, I highly recommend you to use what D_Stark has shown */
22nd Jan 2018, 12:00 PM
Cool Codin
Cool Codin - avatar
+ 3
can we use random class for inputting values??
23rd Jan 2018, 11:03 AM
Shubh Mehrotra
Shubh Mehrotra - avatar