Question

Write a piece of code in Java that sets the value of “int Number” randomly from...

Write a piece of code in Java that sets the value of “int Number” randomly from the following set: {104, 105, 106, 107, 108}.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
piece of code in Java that sets the value of “int Number” randomly from the following set: {104, 105, 106, 107, 108} is

Random rand = new Random();
int arr[] = {104, 105, 106, 107, 108};
int Number = arr[rand.nextInt(arr.length)];
Add a comment
Know the answer?
Add Answer to:
Write a piece of code in Java that sets the value of “int Number” randomly from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Array manipulation (a) Write Java code for a method exchange (int [] a, int i, int...

    Array manipulation (a) Write Java code for a method exchange (int [] a, int i, int j) that exchanges the values stored at indices i and j in the array a. You do not need to worry about cases where either i or j is an invalid index. Give the best estimate you can for its time complexity (b) In an ordered array of n items, how can we determine whether or not an item belongs to the list using...

  • Java BNF How to write pseudocode for this snippet? Java code for finding a prime number...

    Java BNF How to write pseudocode for this snippet? Java code for finding a prime number public class Prime { public static void main(String[] args) { int num = 29; boolean flag = false; for(int i = 2; i <= num/2; ++i) { // condition for nonprime number if(num % i == 0) { flag = true; break; } } if (!flag) System.out.println(num + " is a prime number."); else System.out.println(num + " is not a prime number."); } }

  • Each of the following three data sets represents the 1Q scores of a random sample For...

    Each of the following three data sets represents the 1Q scores of a random sample For each data set, compute the mean and median. of adults. IQ scores are known to have a mean and median of 100. What is the mean of the sample of size 5? Full data set Sample of Size 5 104 108 105 91 Type an integer or decimal rounded to one decimal place as needed.) What is the mean of the sample of size...

  • Problem 1 The following data are from a research project on the effectiveness of a drug in reducing LDL chole...

    Problem 1 The following data are from a research project on the effectiveness of a drug in reducing LDL cholesterol levels. While some patients in the study are assigned to the drug, others were given a placebo. Because the information about who is receiving the actual drug is kept confidential from those taking LDL measurements, that information is kept in a separate data set. Given below in Data Set A are the initial LDL cholesterol level of each individual before...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • 8) Write the Java code to Declare an Integer Number and Initialize it to value 10....

    8) Write the Java code to Declare an Integer Number and Initialize it to value 10. Then use Ternary Operator to Check if the Integer Number is Odd or Even and print out the Result Odd or Even.

  • Write code that sets the value of a variable named result to the sum of the...

    Write code that sets the value of a variable named result to the sum of the values in the variables num1 and num2, unless that sum is in the range 20 to 30, inclusive, in which case set result to 0. Assume num1 and num2 already have values (code in Python).

  • Write Java code using a for loop that is equivalent to the following do-while loop: int...

    Write Java code using a for loop that is equivalent to the following do-while loop: int i = 2 ; do { System.out.println(i + " squared is " + (i * i)) ; i += 2 ; } while (i <= 10) ;

  • Please write the following program in Java: Write the code for  invoking a static method named sendTwo,...

    Please write the following program in Java: Write the code for  invoking a static method named sendTwo, provided by the DataTransmitter class. There are two arguments for this method: a double and an int. Invoke the method with the double value of 15.955 and the int value of 133.

  • write the following code in java thank you and if you can, could you please write...

    write the following code in java thank you and if you can, could you please write the code in replit and sent me a link to it replit is basically like a online compiler and you can write java code on it thank you The first part is to implement one of the questions from your examination. /* A Range objects represents an integer range, such as 1-10 or 50701-50799. The lower and upper bounds of a Range are given...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT