📄 dancelesson2.java
字号:
import java.util.Scanner;
public class DanceLesson2
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter number of male dancers:");
int men = keyboard.nextInt();
System.out.println("Enter number of female dancers:");
int women = keyboard.nextInt();
try
{
if (men == 0 && women == 0)
throw new Exception("Lesson is canceled. No students.");
else if (men == 0)
throw new Exception("Lesson is canceled. No men.");
else if (women == 0)
throw new Exception("Lesson is canceled. No women.");
// women >= 0 && men >= 0
if (women >= men)
System.out.println("Each man must dance with " +
women/(double)men + " women.");
else
System.out.println("Each woman must dance with " +
men/(double)women + " men.");
}
catch(Exception e)
{
String message = e.getMessage( );
System.out.println(message);
System.exit(0);
}
System.out.println("Begin the lesson.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -