java程序求教 编写一个程序实现每隔一秒按顺序依次输出ABCD,依次循环
答案:1 悬赏:30 手机版
解决时间 2021-04-07 11:03
- 提问者网友:情歌越听越心酸
- 2021-04-06 20:16
java程序求教 编写一个程序实现每隔一秒按顺序依次输出ABCD,依次循环
最佳答案
- 五星知识达人网友:轮獄道
- 2021-04-06 21:27
按照你的要求编写的Java程序如下:
public class BC {
public static void main(String[] args) {
Thread_1 t=new Thread_1();
t.start();
}
}
class Thread_1 extends Thread{
int i=0;
public void run(){
while(true){
System.out.print((char)('A'+i));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(i==25){
i=0;
}else{
i++;
}
}
}
}运行结果:
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI
public class BC {
public static void main(String[] args) {
Thread_1 t=new Thread_1();
t.start();
}
}
class Thread_1 extends Thread{
int i=0;
public void run(){
while(true){
System.out.print((char)('A'+i));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(i==25){
i=0;
}else{
i++;
}
}
}
}运行结果:
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯