2013-08-31 33 views
-1

符號在那裏是「;」,所以我不確定語法上的問題是什麼。第17行接收「找不到符號錯誤」

//Vet Application 
import java.io.PrintStream; 

public class VetApp 
{ 
public static void main(String[] paramArrayOfString) 
{ 
Dog newDog1 = new Dog(); 
Dog newDog2 = new Dog(2, "Ruff"); 
System.out.println(); 

System.out.println(); 
newDog1.print(); 
System.out.println(); 
newDog2.print(); 

Scanner localScanner = new Scanner(System.in);

System.out.print("What is the new breed of the first dog? "); 
int i = localScanner.nextInt(); 
newDog1.setBreed(i); 
System.out.println(); 
System.out.println(); 
newDog1.print(); 

System.out.print("What is the breed of the second dog? "); 
i = localScanner.nextInt(); 
newDog2.setBreed(i); 
System.out.println(); 
System.out.println(); 
newDog2.print(); 

System.out.print("What sound does the first dog make? "); 
String str = localScanner.next(); 
newDog1.setSound(str); 
System.out.println(); 
System.out.println(); 
newDog1.print(); 

(本程序的某些被省略)

以下是錯誤消息:

c:\jwork>javac VetApp.java 
MontelWhite_VetApp.java:17: error: cannot find symbol 
Scanner localScanner = new Scanner (System.in); 
^ 
symbol: class Scanner 
location: class VetApp 
MontelWhite_VetApp.java:17: error: cannot find symbol 
Scanner localScanner = new Scanner (System.in); 
         ^
symbol: class Scanner 
location: class VetApp 
2 errors 

如果需要我也有 「狗」 類的源代碼。 我在想什麼/遺忘?

+3

在類文件的頂部添加'import java.util.Scanner'。 –

回答

1

您忘記了爲java.util.Scanner添加導入。因此,請將其添加到類文件的頂部,如下所示:

import java.util.Scanner; 
import java.io.PrintStream; 

public class VetApp { 
    /* Code omitted */ 
}