testinterface.java

来自「Java2入门经典第二章源码」· Java 代码 · 共 25 行

JAVA
25
字号
import java.util.Random;

public class TestInterface
{
  public static void main(String[] args)
  {
    PetOutput[] thePets = {
                            new Dog("Rover", "Poodle"),
                            new Cat("Max", "Abyssinian"),
                            new Duck("Daffy","Aylesbury"),
                            new Spaniel("Fido")
                          };

    PetOutput petChoice;

    Random select = new Random();               // Random number generator
    for(int i = 0; i < 5; i++)
    {
      petChoice = thePets[select.nextInt(thePets.length)];
      System.out.println("\nYour choice:\n" + petChoice);
      petChoice.sound();
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?