2个回答
展开全部
package test;
public class Test {
public static void main(String[] args) {
new Thread(new TestThread(1)).start();
new Thread(new TestThread(2)).start();
}
}
class TestThread implements Runnable{
private int num;
public TestThread(int num){
this.num = num;
System.out.println("This is thread"+num);
}
public void run() {
for(int i=1;i<=100;++i){
System.out.println(i);
}
}
}
public class Test {
public static void main(String[] args) {
new Thread(new TestThread(1)).start();
new Thread(new TestThread(2)).start();
}
}
class TestThread implements Runnable{
private int num;
public TestThread(int num){
this.num = num;
System.out.println("This is thread"+num);
}
public void run() {
for(int i=1;i<=100;++i){
System.out.println(i);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package baidu;
public class Baidu implements Runnable {
public Baidu() {
}
private String str1 = "";
private String str2 = "";
private String str3 = "";
private String str4 = "";
private static String temp;
public void run() {
for (int i = 1; i <= 100; i++) {
System.out.println(String.valueOf(i));
}
}
public static void main(String args[])
{
Thread thread = new Thread(new Baidu());
thread.start();
try {
thread.sleep(1000);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println("End");
thread = new Thread(new Baidu());
thread.start();
try {
thread.sleep(1000);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println("End all");
}
}
public class Baidu implements Runnable {
public Baidu() {
}
private String str1 = "";
private String str2 = "";
private String str3 = "";
private String str4 = "";
private static String temp;
public void run() {
for (int i = 1; i <= 100; i++) {
System.out.println(String.valueOf(i));
}
}
public static void main(String args[])
{
Thread thread = new Thread(new Baidu());
thread.start();
try {
thread.sleep(1000);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println("End");
thread = new Thread(new Baidu());
thread.start();
try {
thread.sleep(1000);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println("End all");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |