Question

JAVA: Write the Psuedocode for a generic algorithm that uses the .nextINT method on an object...

JAVA: Write the Psuedocode for a generic algorithm that uses the .nextINT method on an object to generate a random number in the range min to max where min and max are integers.

Homework Answers

Answer #1

Psuedocode:

start:

int max=10;

int min=5;

Random random = new Random();

int randomNum = random.nextInt((max - min + 1) + min;

print randomNum;

end;

Java Code:

import java.util.Random;

public class RandomNumTest {

   public static void main(String[] args) {
       //creating Random class object
       Random random = new Random();
       int randomNum = random.nextInt((max - min) + 1) + min;
       System.out.println("Random number:"+randomNum);
   }
}
Output:

Random number:7

Know the answer?
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
Similar Questions
Write a java program to display a given range of integer numbers (0 to 9) in...
Write a java program to display a given range of integer numbers (0 to 9) in the following order: Example : given (5 to 9), the program displays 56789 67895 78956 89567 95678 The first line displays the min to max range. Each line that follows should display the next higher number except when it hits the maximum number. In that situation, the line wraps back to the minimum sequence. For this problem write a static method to do the...
Language: JAVA(Netbeans) Write a generic class MyMathClass with at type parameter T where T is a...
Language: JAVA(Netbeans) Write a generic class MyMathClass with at type parameter T where T is a numeric object (Integer, Double or any class that extends java.lang.number) Add a method standardDeviation (stdev) that takes an ArrayList of type T and returns a standard deviation as type double. Use a for each loop where appropriate. Hard code a couple of test arrays into your Demo file. You must use at least 2 different types such as Double and Integer. Your call will...
This is JAVA Write the method findMin that will return the smallest number in an array...
This is JAVA Write the method findMin that will return the smallest number in an array of integers. Examples: findMin({29,2,32,12}) -> 2 public int findMin(int[] numbers) {    }
1.        A. Write a recursive brute force algorithm that calculates an. B. Write the java code...
1.        A. Write a recursive brute force algorithm that calculates an. B. Write the java code that does the calculation. C. What is the recurrence relation for the number of multiplications? D. What is the efficiency class of the algorithm?
Java Write a method that uses an ArrayList and its contains method to take an input...
Java Write a method that uses an ArrayList and its contains method to take an input array of strings return a new array, free of any duplicate strings.
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns...
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns a 2D array of integers of size rows x cols where the value of element [row][col] is row + col. Write a short program to test your method.
Write a method that take in an array of integers, find the maximum and minimum, and...
Write a method that take in an array of integers, find the maximum and minimum, and return an array containing four elements in the following order. max integer, max integer index, min integer, min integer index
Write an application in Java which includes an algorithm that takes an array of any size,...
Write an application in Java which includes an algorithm that takes an array of any size, selects the high and low integer from the array of integers with each pass and builds a new array of integers by inserting the high and low selection with each pass. Your output should show the original array of integers and the output of each pass on a new line. Note: You can assume all integers are positive, but your code must work for...
Using Java write all 4 methods in one class 1) Write a value-returning method that returns...
Using Java write all 4 methods in one class 1) Write a value-returning method that returns the number of elements in an integer array. 2) Write a void method that multiples by 2 all the elements in an array of float. 3) Write a value- returning method that returns the product of all elements in an integer array. 4) Write a method that returns the total # of elements greater or equal to 90 in an array of integers.
Write an algorithm to check equality of two link lists. IN JAVA OR PSEUDOCODE
Write an algorithm to check equality of two link lists. IN JAVA OR PSEUDOCODE
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT