Java Reference
In-Depth Information
< Day Day Up >
Puzzle 82: Beer Blast
Several puzzles in this chapter involved multiple threads, but this one involves multiple processes.
What does this program print if you run it with the single command line argument slave ? What
does it print if you run it with no command line arguments?
public class BeerBlast {
static final String COMMAND = "java BeerBlast slave";
public static void main(String[] args) throws Exception {
if (args.length == 1 && args[0].equals("slave")) {
for (int i = 99; i > 0; i--) {
System.out.println(i +
" bottles of beer on the wall");
System.out.println(i + " bottles of beer");
System.out.println(
"You take one down, pass it around,");
System.out.println((i-1) +
" bottles of beer on the wall");
System.out.println();
}
} else {
// Master
Process process = Runtime.getRuntime().exec(COMMAND);
int exitValue = process.waitFor();
System.out.println("exit value = " + exitValue);
}
}
 
 
Search WWH ::




Custom Search