我模拟一个:public class Test2 {
static String a;
public static void main(String[] args) throws InterruptedException {
T t = new T();
t.setDaemon(true);
t.start();
System.out.print("等待用户输入:");
Thread.sleep(3000);
if(a==null){
System.out.println("no");
}else{
System.out.println(a);
}
System.out.println("over");
}}
class T extends Thread{
@Override
public void run() {
Test2.a = new Scanner(System.in).nextLine();
}
}
static String a;
public static void main(String[] args) throws InterruptedException {
T t = new T();
t.setDaemon(true);
t.start();
System.out.print("等待用户输入:");
Thread.sleep(3000);
if(a==null){
System.out.println("no");
}else{
System.out.println(a);
}
System.out.println("over");
}}
class T extends Thread{
@Override
public void run() {
Test2.a = new Scanner(System.in).nextLine();
}
}
解决方案 »
- the method setOnKeyListener in the type View is not a applicable for the argumen
- 请教创建类实例时Java虚拟机的操作过程
- 谁帮忙解释一下这个错误的产生 感激不尽
- 急求....生成甘特图....与微软的project相似
- hashmap死循环
- 怎么把字符串转为java.sql.Date 类型?
- NoClaDefFoundError
- 请问沈阳有没有sun授权的考试中心?
- Java与数据库jdbc.odbc桥连接的问题
- Help!!!
- 这个程序先是顺序输出接着是反序输出,previous用错在哪里
- 怎么生成一个圆并保存为图片文件?
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
long startTime = System.currentTimeMillis();
String line = null;
try {
while ((System.currentTimeMillis() - startTime) < time * 1000
&& !in.ready()) {
}
if (in.ready()) { line = in.readLine();
} else {
// System.out.println("You did not enter data");
line = "-1";
}
} catch (IOException e) {
e.printStackTrace();
}
return line; }