日期:2014-05-20  浏览次数:20913 次

怎么打印数字时候会显示正方形???那里错了?怎么修改?
public class MyThread implements Runnable {
private char n;
private int time;
private char i;

public MyThread(char n, int time) {
this.n = n;
this.time = time;
}

public void run() {

if (n == '1') {
for (char i = 1; i <= 26; i++) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print(" " + i);
}
}

else if (n == 'A') {
for (char i = 'A'; i <= 'Z'; i++) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print(" " + i);
}
} else {
for (char i = 'a'; i <= 'z'; i++) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print(" " + i);
}
}

}

public static void main(String[] args) {

MyThread t1 = new MyThread('A', 1000);
Thread t = new Thread(t1);
t.start();
MyThread t2 = new MyThread('a', 2000);
Thread tt = new Thread(t2);
tt.start();
MyThread t3 = new MyThread('1', 3000);
Thread ttt = new Thread(t3);
ttt.start();
}
}


------解决方案--------------------
if (n == '1') {
for (char i = 1; i <= 26; i++) {

===>

if (n == '1') {
for (int i = 1; i <= 26; i++) {
------解决方案--------------------
for (char i = 1; i <= 26; i++) 你声明的是char类型的i 换成int类型 不就能打印出数字啦 主要原因你自己去查查 char int 的区别就明白啦