-1
import java.util.*;
class AddressBook {
private static final int DEFAULT_SIZE = 25;
private Person[] entry; //getting error - cannot be resolved to a type
public AddressBook() {
this(DEFAULT_SIZE);
}
public AddressBook(int size) {
if (size <= 0) {
throw new IllegalArgumentException("Size must be positive");
}
entry = new Person[size]; // cannot be resolved to a type
System.out.println("array of " + size + " is created");
}
}
import java.util.Scanner;
class TestAddressBook {
public static void main(String args[]) {
AddressBook myBook;
String inputStr;
int size;
Scanner scanner = new Scanner(System.in);
while(true) {
System.out.print("array size: ");
inputStr = scanner.next();
if (inputStr.equalsIgnoreCase("stop")) {
break;
}
size = Integer.parseInt(inputStr);
try {
myBook = new AddressBook(size);
}
catch (IllegalArgumentException e) {
}
System.out.println("Exception thrown: size = " + size);
}
}
}
我找不出什麼類型的我應該與數組一起使用,以使一切正常工作。 私人[]條目; //獲取錯誤 - 無法解析爲類型 .... entry = new Person [size]; //無法解析爲某個類型錯誤:無法解析到一個類型