How to generate an int randomly within given range using Math - Java Language Basics

Java examples for Language Basics:Math

Description

How to generate an int randomly within given range using Math

Demo Code


public class Main {
        public static void main(String args[]){
                int random = (int)(Math.random()* 10 ) + 5;
                System.out.println(random);
        }/*from   w  w w .  j  a v a  2 s.  c  om*/
}

Result


Related Tutorials