Java Program to generate random numbers between 1 to 10


In this program, You will learn how to generate random numbers from 1 to 10 in java.


Generate Random number

((int) (Math.random() * (10 - 2)) + 2)

Example: How to generate random numbers between 1 to 10 in java.

class Main {

    public static void main(String args[]) {

        for (int i = 1; i <= 10; i++) {

            System.out.print("Random Number is :");
            System.out.println((int) (Math.random() * (10 - 2)) + 2);
        }

    }
}

Output:

Random Number is :4
Random Number is :9
Random Number is :6
Random Number is :5
Random Number is :8
Random Number is :8
Random Number is :7
Random Number is :9
Random Number is :3
Random Number is :9

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.