0% found this document useful (0 votes)
17 views

Rand

This Java code generates 5 random numbers within a range of minimum and maximum values input by the user using Math.random() and prints the results. It imports java.util, declares variables to store the min, max, and random values, gets user input for the range, generates random ints in a for loop, and prints the output.

Uploaded by

ANIKET RAWAT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Rand

This Java code generates 5 random numbers within a range of minimum and maximum values input by the user using Math.random() and prints the results. It imports java.util, declares variables to store the min, max, and random values, gets user input for the range, generates random ints in a for loop, and prints the output.

Uploaded by

ANIKET RAWAT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

*;
class rand
{
public static void main( String args[] )
{ String s1,s2;
int min ;
int max;
Scanner sc=new Scanner(System.in);
System.out.println("enter minimum range");
s1=sc.nextLine();
min=Integer.parseInt(s1);
System.out.println("enter maximum range");
s2=sc.nextLine();
max=Integer.parseInt(s2);
for(int i=0;i<5;++i)
{
//Generate random int value from 50 to 100
System.out.println("Random value in int from "+min+" to "+max+ ":");
int random_int = (int)(Math.random() * (max - min + 1) + min);
System.out.println(random_int);
}
}
}

You might also like