Question #250152

1. Write a program that generates a random number between 0 to 10. Use the following statements below for generating random number and the class Random from the package java.util:Random rand = new Random();int num = rand.nextInt(10);2. Display the generated random number with text: "The generated random number between 0 to 10 is: ".3. Name the class as RandomNumber and save the file.4. Compile and execute the program using the command prompt (cmd). If you do not have cmd, run it in JDoodle.5. Correct syntax and logical errors if there are any.6. Once you have successfully compiled and execute the program, copy the source code and paste it here in the Submission box.

Expert's answer

import java.util.Random;
public class Main
{
	public static void main(String[] args) {
		Random rand;
        rand = new Random();
        int num = rand.nextInt(10);
        System.out.println("The generated random number between 0 to 10 is: "+num);
	}
}

LATEST TUTORIALS
APPROVED BY CLIENTS