Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Random numbers are useful for lots of different programming tasks, including gaming, simulation, etc. Java API provides a Random class that you can use

Java

Random numbers are useful for lots of different programming tasks, including gaming, simulation, etc. Java API provides a Random class that you can use to generate random numbers. To use Random class to generate random integers, follow these steps:

This class is part of the java.util package, so any program that uses it will need an import statement such as: import java.util.Random;

Create an object from the Random class with: Random random = new Random();

Call the nextInt() method or nextInt(int n) method to generate a random integer. For example:

int number = random.nextInt(); //number can be any integer in the range of an int type.

int number = random.nextInt(100);//number can be somewhere between 0 and 99.

In this activity, work with your team to define a method that takes an integer parameter n and returns an integer array of length n. The method generates n unique random numbers, with each number between 0 and n-1. These numbers are stored in an array, which is returned by the method. For example, if the method input is 4, then a possible return value can be {0, 3, 2, 1}. Note that each element in the array is unique.

Work with your team to complete the following:

1. On paper, write pseudocode instructions to solve the problem.

2. Implement your pseudocode in zyBook section 17.2.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

=+ Who has this information?

Answered: 1 week ago

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago

Question

2 The role of economic theory in economics.

Answered: 1 week ago