Write a short snippet of code that converts the first element of the String[] args array to an integer. It should catch an exception and print out a message if the first element cannot be converted to an integer.
What will be an ideal response?
```
int number;
try {
number = Integer.parseInt(number);
}
catch(NumberFormatException nfe) {
System.out.println("The first argument to the command line"
+ " is not an integer; try again.");
System.exit(0);
}
```
Computer Science & Information Technology
You might also like to view...
Which of the following Windows Media Player formats only contains the playback controls?
A) skin mode B) full mode C) compact mode D) expanded mode
Computer Science & Information Technology
How does a program recognize the end of an input file?
What will be an ideal response?
Computer Science & Information Technology