你好,运行时,输入了Q但是程序没有退出还在一直执行,是什么原因,蒙圈
```java
package homework;
import java.util.Scanner;
/**
* @author 小池
* @version 1.0
*/
public class HomeWork01 {
public static void main(String[] args) {
A a = new A();
a.start();
B b = new B();
Thread thread = new Thread(b);
thread.start();
}
}
class A extends Thread {
private static boolean loop = true;
public static boolean isLoop() {
return loop;
}
public static void setLoop(boolean loop) {
A.loop = loop;
}
@Override
public void run() {
while (loop) {
for (int i = 0; i < 100; i++) {
System.out.println((int) (Math.random() * 100+1));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
class B implements Runnable {
Scanner scanner = new Scanner(System.in);
@Override
public void run() {
for (;;) {
System.out.println("是否要中断A线程的运行? 请输入选择 Q:中断");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
char c = scanner.next().toUpperCase().charAt(0);
if (c=='Q') {
A.setLoop(false);
break;
}
}
}
}
```