Write a short program that allows the user to input a positive integer and then outputs a randomly generated integer between 1 and the input number.
What will be an ideal response?
```
import java.util.Scanner;
import java.util.Random;
public class RandomInteger {
public static void main(String [] args) {
int inputNum, randNum;
Scanner input = new Scanner(System.in);
Random generator = new Random();
System.out.print("Please enter a positive integer: ");
inputNum = input.nextInt();
randNum = generator.nextInt(inputNum) + 1;
System.out.println("Your random number is " + randNum + ".");
}//end main
}//end class
```
You might also like to view...
What is the most likely problem if a laser printer outputs streaks on every page?
A) Paper quality B) Photosensitive drum C) Fuser assembly D) Paper path rollers
Which of the following statements is false?
a. The ARPANET is the precursor to today’s Internet. b. Today’s fastest Internet speeds are on the order of trillionsof bits per second with quadrillion-bit-per-second speeds on the horizon. c. Although the ARPANET enabled researchers to network their computers, its main benefit proved to be the capability for quick and easy communication via what came to be known as electronic mail (e-mail). d. The protocol (set of rules) for communicating over the ARPANET became known as the Transmission Control Protocol (TCP). TCP ensured that messages, consisting of sequentially numbered pieces called packets, were properly routed from sender to receiver, arrived intact and were assembled in the correct order.