Java Reference
In-Depth Information
Display 9.1 Handling a Special Case without Exception Handling (part 2 of 2)
Sample Dialogue 1
Enter number of male dancers:
4
Enter number of female dancers:
6
Each man must dance with 1.5 women.
Begin the lesson.
Sample Dialogue 2
Enter number of male dancers:
0
Enter number of female dancers:
0
Lesson is canceled. No students.
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.2 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();
(continued)
 
Search WWH ::




Custom Search