35 lines
956 B
Java
Raw Normal View History

2015-12-15 11:47:04 -08:00
// collectionsindepth/RandomBounds.java
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
2015-06-15 17:47:35 -07:00
// Does Math.random() produce 0.0 and 1.0?
// {Args: lower}
2016-07-07 14:58:56 -06:00
import onjava.*;
2015-06-15 17:47:35 -07:00
public class RandomBounds {
static void usage() {
2015-11-03 12:00:44 -08:00
System.out.println("Usage:");
System.out.println("\tRandomBounds lower");
System.out.println("\tRandomBounds upper");
2015-06-15 17:47:35 -07:00
System.exit(1);
}
public static void main(String[] args) {
if(args.length != 1) usage();
2016-07-07 14:58:56 -06:00
new TimedAbort(3);
2015-06-15 17:47:35 -07:00
switch(args[0]) {
case "lower":
while(Math.random() != 0.0)
; // Keep trying
2015-11-03 12:00:44 -08:00
System.out.println("Produced 0.0!");
2015-06-15 17:47:35 -07:00
break;
case "upper":
while(Math.random() != 1.0)
; // Keep trying
2015-11-03 12:00:44 -08:00
System.out.println("Produced 1.0!");
2015-06-15 17:47:35 -07:00
break;
default:
usage();
}
}
2015-09-07 11:44:36 -06:00
}