Computer Science, asked by BrainlyProgrammer, 1 month ago

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 ShreyasKulkarni2006
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);

}

}

}


Oreki: Please check your answer, there does not exist any constructor like Random(int, int), only Random( ) and Random(long) exist.
ShreyasKulkarni2006: ohk thanks a lot
BrainlyProgrammer: @ShreyasKulkarni2006 better luck next time :)
ShreyasKulkarni2006: thank You
Answered by anindyaadhikari13
3

Required Answer:-

Question:

  • Write a program in Java to print 10 random numbers between 27 and 97.

Solution:

Here is the program.

  1. public class Random {
  2. public static void main(String[] args) {
  3. for(int i=1;i<=10;i++)
  4. System.out.println((int)(Math.random()*(97-27)+27));
  5. }
  6. }

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:

anindyaadhikari13: Thanks for the brainliest!!
BrainlyProgrammer: Brainliest doesn't matter....but yout answer matters...your answer is given with great explaination so that's why you got brainliest
anindyaadhikari13: Thank you :)
Similar questions