New Question!!
WAP in JAVA to print 10 random numbers between 27 and 97.
_
#BeBrainly
•No irrelevant answers and comments
Oreki:
Bounds inclusive or exclusive?
Answers
Answered by
2
Answer:
import java.util.Random;
public class RandomNumbers{
public static void main(String[] args) {
Random objGenerator = new Random(27,97);
for (int iCount = 0; iCount< 10; iCount++){
int randomNumber = objGenerator.nextInt(100);
System.out.println("Random No : " + randomNumber);
}
}
}
Answered by
3
Required Answer:-
Question:
- Write a program in Java to print 10 random numbers between 27 and 97.
Solution:
Here is the program.
- public class Random {
- public static void main(String[] args) {
- for(int i=1;i<=10;i++)
- System.out.println((int)(Math.random()*(97-27)+27));
- }
- }
Explanation:
- Syntax to generate random number between m and n is - (int)(Math.random()*(m - n) + m)
- Using this logic, we have displayed 10 random numbers between 27 and 97.
Attachments:
Similar questions