我在本书的本书中的演示代码中收到无法访问的语句错误
System.out.print("Contents of bigQ: ");
这是代码的其余部分。
class demonstration {
public static void main(String args[]) {
qdsd bigQ = new qdsd(100);
qdsd smallQ = new qdsd(4);
char ch;
int i;
System.out.println("Using bigQ to store the alphabet.");
// put some numbers into bigQ
for(i = 0; 9 <26;i++)
bigQ.put((char) ('A' + i));
// retrieve and display elements form bigQ
System.out.print("Contents of bigQ: ");
for(i = 0; i < 26; i++) {
ch = bigQ.get();
if(ch != (char) 0) System.out.print(ch);
}
System.out.println("\n");
System.out.print("Using smallQ to print out some errors.");
// Now, use smallQ to generatate some errors
for(i=0;i<5;i++){
System.out.println("Attempting to store " +
(char) ('Z' - i));
System.out.println();
}
System.out.println();
// more errors on smallQ
System.out.print("Contents of smallQ: ");
for(i=0;i<5;i++){
ch = smallQ.get();
if(ch != (char) 0) System.out.print(ch);
}
}
}
答案 0 :(得分:3)
那是因为它之前有一个无限循环:
for(i = 0; 9 <26;i++)
bigQ.put((char) ('A' + i));
由于9 < 26
总是为真,所以循环将永远执行。你的意思是这样做吗?:
for(i = 0; i <26;i++)
bigQ.put((char) ('A' + i));
答案 1 :(得分:1)
对于循环条件(9 <26
)使其成为无限循环。