【发布时间】:2015-07-29 08:03:40
【问题描述】:
我在清除案例 2 和案例 3 的第二行预期的以下错误 '(' 或 '[' 时遇到问题。我编写的代码是 newAnimal.displayInfo();
我不确定为什么我在案例 2 和 3 中收到此错误,但在案例 1 中没有。不确定我做错了什么。任何帮助/指导将不胜感激。
代码如下:
package animalinfo;
import java.util.Scanner;
public class AnimalInfo
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
Scanner input = new Scanner (System.in);
Animal newAnimal;
int quit = 4;
while(-4 != quit);
{
System.out.println("\n1) Camel" +
"\n2)Penguin" +
"\n3) Tortoise" +
"\n4) Exit Program.");
System.out.print("Please select an amimalfrom the list.");
int choice = input.nextInt();
switch (choice)
{
case 1:
newAnimal = new Camel();
newAnimal.displayInfo();
break;
case 2:
newAnimal = new Penguin
newAnimal.displayInfo();
break;
case 3:
newAnimal = new Tortoise
newAnimal.displayInfo();
break;
case 4:
System.out.println ("Thank you for making your selections.");
break;
}
}
}
}
【问题讨论】:
标签: java