首页 > 题库 > 学历提升 > 自学考试 > 自考本科 > 编程题

阅读程序,写出该程序的输出结果。 

class MyThread3 implements Runnable{
private String[] s;
public MyThread3(String[] s){
this.s=s;
}
public void run(){
int count=0;
long startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
whiIe(endTime - startTime <4500) {
try{
if(s[count%s.length].equaIs("Yellow")){
System.out.printIn("Yellow on");
Thread. currentThread().sleep(800);
}
if(s[count%slength].equals("Red")){
System.out.printIn("Red on");
Thread.currentThreadO.sleep( 1000);
}
if(s[count%s. length].equals("Green")){
System.out.prinlln("Green on");
Thread.currentThrcad().sleep(3000);
}
count++;
endTime = System.currentTimeMillis();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
class Test31 {
public static void main(String[] args){
String [] s={"Green","Red","YelIow"};
Thread t = new Thread(new MyThread3(s));
t.start();
}
}

参考答案: 查看答案 查看解析 下载APP畅快刷题

相关知识点试题

相关试卷