1.老师,请教怎么怎么实现循环赋值
package com.imooc.runable;
public class Letter implements Runnable {
public letter() {
char charArray[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'g', 'k', 'i', 'l', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
System.out.println(charArray);
}
@Override
public void run() {
for (int i = 0; i <= 25; i++) {
System.out.println("第" + (i + 1) + "次" + "正在输出字母" + Thread.currentThread().getName());
try {
Thread.sleep(26);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Letter myLetter = new Letter();
Thread tm1 = new Thread(myLetter);
tm1.start();
}
}
输出结果:
第1次正在输出字母Thread-0
第2次正在输出字母Thread-0
第3次正在输出字母Thread-0
第4次正在输出字母Thread-0
第5次正在输出字母Thread-0
第6次正在输出字母Thread-0
第7次正在输出字母Thread-0
第8次正在输出字母Thread-0
第9次正在输出字母Thread-0
第10次正在输出字母Thread-0
第11次正在输出字母Thread-0
第12次正在输出字母Thread-0
第13次正在输出字母Thread-0
第14次正在输出字母Thread-0
第15次正在输出字母Thread-0
第16次正在输出字母Thread-0
第17次正在输出字母Thread-0
第18次正在输出字母Thread-0
第19次正在输出字母Thread-0
第20次正在输出字母Thread-0
第21次正在输出字母Thread-0
第22次正在输出字母Thread-0
第23次正在输出字母Thread-0
第24次正在输出字母Thread-0
第25次正在输出字母Thread-0
第26次正在输出字母Thread-014
收起
正在回答 回答被采纳积分+1
1回答
Java零基础入门18
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星