上交作业了

来源:3-6 自由编程

慕沐1462760

2020-08-13 11:11:00

public class Letter implements Runnable {


@Override

public void run() {

char[]ch=new char [26];

Scanner sc=new Scanner(System.in);

for(int i=1;i<=26;i++) {

ch[i-1]=sc.next().charAt(0);

}

sc.close();

for(char a:ch) {

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

System.out.print(a+" ");


}


}


}





public class Test {


public static void main(String[] args) {

Letter lt=new Letter();

Thread td=new Thread(lt);

td.start();


}


}


写回答

1回答

好帮手慕小脸

2020-08-13

同学你好,根据作业要求利用线程输出“a~z”的26个字母(横向输出),要求每隔一秒钟输出一个字母,这里并不是手动输入。

同学可根据作业要求更改代码内容:

http://img.mukewang.com/climg/5f34b6e3094fe05a07470238.jpg

例如:

public class Letter implements Runnable {
    char[] letter = new char[26];
    public Letter(){
        int i=0;
        for (char j = 'a'; j<='z'; j++) {
            letter[i] = j;
            i++;
        }
    }
    public void run() {
        for (char ch:letter) {
            System.out.print(ch+" ");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
public static void main(String[] args) {
		Letter lt=new Letter();
		Thread td=new Thread(lt);
		td.start();
	}

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

0

0 学习 · 16556 问题

查看课程