Java Reference
In-Depth Information
Display 9.2
Handling a Special Case without Exception Handling
(part 3 of 3)
Sample Dialogue 3
Enter number of male dancers:
0
Enter number of female dancers:
5
Lesson is canceled. No men.
Sample Dialogue 4
Enter number of male dancers:
4
Enter number of female dancers:
0
Lesson is canceled. No women.
Display 9.3
Same Thing Using Exception Handling
(part 1 of 3)
1
import
java.util.Scanner;
2
public class
DanceLesson2
3 {
4
public static void
main(String[] args)
5 {
6 Scanner keyboard =
new
Scanner(System.in);
7 System.out.println("Enter number of male dancers:");
8
int
men = keyboard.nextInt();
9 System.out.println("Enter number of female dancers:");
10
int
women = keyboard.nextInt();
This is just a toy example to learn Java syntax. Do not take it
as an example of good typical use of exception handling.
(continued)