-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebugSix4.java
More file actions
43 lines (42 loc) · 1.38 KB
/
DebugSix4.java
File metadata and controls
43 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// DebugSix4.java
// Displays 5 random numbers between
// (and including) user-specified values
import java.util.Scanner;
public class DebugSix4
{
public static void main(String[] args)
{
int high, low, count;
final int NUM = 5;
Scanner input = new Scanner(System.in);
// Prompt user to enter high and low values
System.out.print("This application displays " + NUM +
" random numbers" +
"\nbetween the low and high values you enter" +
"\nEnter low value now... ");
low = input.nextInt();
System.out.print("Enter high value... ");
high = input.nextInt();
while(low == high)
{
System.out.println("The number you entered for a high number, " +
high + ", is not more than " + low);
System.out.print("Enter a number higher than " + low + "... ");
high = input.nextInt();
}
while(count < low)
{
double result = Math.random();
// random() returns value between 0 and 1
int answer = (int) (result * 10 + low);
// multiply by 10 and add low -- random is at least the value of low
// only use answer if it is low enough
if(answer <= low)
{
System.out.print(answer + " ");
++count;
}
}
System.out.println();
}
}