多线程实现排序:总是提示main函数有问题 另外如果数组先不给定,如何实现
import java.io.*;
public class pai
{
public static void main(String args[])
{
bigtosmall btos=new bigtosmall("btos");
smalltobig stob=new smalltobig("stob");
Thread t1 = new Thread (btos);
Thread t2 = new Thread (stob);
new Thread (btos).start();
new Thread (stob).start();
}
}class bigtosmall implements Runnable{
int a[]={1,33,25,14,42,86,58,37,69,10};
private String id;
public bigtosmall(String str)
{
id=str;
}
public void run()
{
int i,j=0;
for( i=0;i<9;i++)
for(j=i+1;j<10;j++);
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
for(int k=0;k<10;k++)
System.out.println(a[k] ) ;
}
}///////////////
class smalltobig implements Runnable
{
int a[]={1,33,25,14,42,86,58,37,69,10};
private String id;
public smalltobig(String str)
{
id=str;
}
public void run()
{
int i, j;int temp=a[0];
for( i=0;i<9;i++)
{
for( j=i+1;j<10;j++);
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
System.out.println("the result is :");
for(int k=0;k<10;k++)
System.out.println(a[k]+" " ) ;
}
}
}
import java.io.*;
public class pai
{
public static void main(String args[])
{
bigtosmall btos=new bigtosmall("btos");
smalltobig stob=new smalltobig("stob");
Thread t1 = new Thread (btos);
Thread t2 = new Thread (stob);
new Thread (btos).start();
new Thread (stob).start();
}
}class bigtosmall implements Runnable{
int a[]={1,33,25,14,42,86,58,37,69,10};
private String id;
public bigtosmall(String str)
{
id=str;
}
public void run()
{
int i,j=0;
for( i=0;i<9;i++)
for(j=i+1;j<10;j++);
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
for(int k=0;k<10;k++)
System.out.println(a[k] ) ;
}
}///////////////
class smalltobig implements Runnable
{
int a[]={1,33,25,14,42,86,58,37,69,10};
private String id;
public smalltobig(String str)
{
id=str;
}
public void run()
{
int i, j;int temp=a[0];
for( i=0;i<9;i++)
{
for( j=i+1;j<10;j++);
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
System.out.println("the result is :");
for(int k=0;k<10;k++)
System.out.println(a[k]+" " ) ;
}
}
}
解决方案 »
- [服务端建立文档]在tomcat服务器项目下的目录里进行文件创建的一些问题
- 怎么能把一个对象存为文件,然后在从文件读出这个对象然后操作啊?能做吗?
- 刚开始学java,问一个很基本的问题
- 如何动态创建所需要的类??和相应的属性?
- [求助]关于JComboBox<组合框>如何提取的问题~<----------高手来啊-------->
- 刚刚写了一个单纯形算法,请大家帮忙优化!
- 请教一个jdbc远程访问的问题!!!!
- 关于Applet,急!
- 用文本编辑器编译java源文件,出现这个字符集问题。。。求解。。。。
- java swing之jsplitpane
- 正则表达式,sswater(光杆兵)等高手请进!
- 给位请问JCreator是什么?
public class pai
{
public static void main(String args[])
{
bigtosmall btos=new bigtosmall("btos");
smalltobig stob=new smalltobig("stob");
Thread t1 = new Thread (btos);
Thread t2 = new Thread (stob);
new Thread (btos).start();
new Thread (stob).start();
}
}class bigtosmall implements Runnable{
int a[]={1,33,25,14,42,86,58,37,69,10};
private String id;
public bigtosmall(String str)
{
id=str;
}
public void run()
{
int i,j=0;
for( i=0;i<9;i++)
for(j=i+1;j<10;j++) // 去掉分号
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
for(int k=0;k<10;k++)
System.out.println(a[k] ) ;
}
}///////////////
class smalltobig implements Runnable
{
int a[]={1,33,25,14,42,86,58,37,69,10};
private String id;
public smalltobig(String str)
{
id=str;
}
public void run()
{
int i, j;int temp=a[0];
for( i=0;i<9;i++)
{
for( j=i+1;j<10;j++) // 去掉分号
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
System.out.println("the result is :");
for(int k=0;k<10;k++)
System.out.println(a[k]+" " ) ;
}
}
}
public class pai
{
public static void main(String args[])
{
int[] a1 = {1,33,25,14,42,86,58,37,69,10};
int[] a2 = {1,33,25,14,42,86,58,37,69,10};
bigtosmall btos=new bigtosmall("btos",a1);
smalltobig stob=new smalltobig("stob",a2);
Thread t1 = new Thread (btos);
Thread t2 = new Thread (stob);
new Thread (btos).start();
new Thread (stob).start();
}
}class bigtosmall implements Runnable{
int[] a;
private String id;
public bigtosmall(String str ,int[] a)
{
id=str;
this.a = a;
}
public void run()
{
int i,j=0;
for( i=0;i<a.length - 1;i++)
for(j=i+1;j<a.length ;j++) // 去掉分号
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
for(int k=0;k<a.length;k++)
System.out.println(a[k] ) ;
}
}///////////////
class smalltobig implements Runnable
{
int[] a ; //={1,33,25,14,42,86,58,37,69,10};
private String id;
public smalltobig(String str ,int[] a)
{
id=str;
this.a = a;
}
public void run()
{
int i, j;int temp=a[0];
for( i=0;i<a.length - 1;i++)
{
for( j=i+1;j<a.length ;j++) // 去掉分号
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
System.out.println("the result is :");
for(int k=0;k<a.length;k++)
System.out.println(a[k]+" " ) ;
}
}
}