JAVA网络及数据库开发 5
用Thread类和Runnable接口实现在控制台上打印大写A—Z和它的ASC||码。要求:第一个类继承Thread类并打印字母。第二个类实现Runnable接口打印AS...
用Thread类和Runnable接口实现在控制台上打印大写A—Z和它的ASC||码。要求:第一个类继承Thread类并打印字母。第二个类实现Runnable接口打印ASC||码,在Main类里只能启动第一个线程,而第二个线程要求在第一个线程中启动,第一个线程要求把ASC||码传给第二个线程。
展开
1个回答
展开全部
public class PrintThread extends Thread{
private String s = "abcdefghijklmnopqrstuvwxyz";
@Override
public void run(){
char[] cc = s.toCharArray();
int[] ii = new int[26];
for(int i = 0; i < cc.length; i++){
System.out.print(cc[i]);
System.out.print(" ");
}
System.out.println();
for(int i = 0; i < cc.length; i++){
ii[i] = (int)cc[i];
System.out.print(ii[i]);
System.out.print(" ");
}
System.out.println();
new Thread(new PrintRunable(ii)).start();
}
public static void main(String[] args) {
new PrintThread().start();
}
}
class PrintRunable implements Runnable{
private int[] cc = new int[26];
public PrintRunable(int[] cc){
this.cc = cc;
}
@Override
public void run() {
for(int i = 0; i < cc.length; i++){
System.out.print(cc[i]);
System.out.print(" ");
}
}
}
private String s = "abcdefghijklmnopqrstuvwxyz";
@Override
public void run(){
char[] cc = s.toCharArray();
int[] ii = new int[26];
for(int i = 0; i < cc.length; i++){
System.out.print(cc[i]);
System.out.print(" ");
}
System.out.println();
for(int i = 0; i < cc.length; i++){
ii[i] = (int)cc[i];
System.out.print(ii[i]);
System.out.print(" ");
}
System.out.println();
new Thread(new PrintRunable(ii)).start();
}
public static void main(String[] args) {
new PrintThread().start();
}
}
class PrintRunable implements Runnable{
private int[] cc = new int[26];
public PrintRunable(int[] cc){
this.cc = cc;
}
@Override
public void run() {
for(int i = 0; i < cc.length; i++){
System.out.print(cc[i]);
System.out.print(" ");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询