JAVA2程序设计实用教程之Java的面向对象特征上机报告|上机实验实习报告|计算机上机实习报告|利用线程比较插入冒泡排序算法的运行时间
实验目的
掌握Java的面向对象特征。
二、所用仪器、材料(设备名称、型号、规格等)
个人计算机一台
三、实验内容
class Paixu{
public static void main(String [] ags)
{
int a[]={79,22,20,36,82,90,10};
(new Threadchru(a,7)).start();
(new Threadmaopao(a,7)).start();
}
}
class Threadchru extends Thread
{
private int b;
int i=0,j=0,n=7;
int a[];
public Threadchru(int a1[],int n)
{
this.a=a1;
this.n=n;
}
public void run()
{
System.out.println(getName()+"insert:");
while(i<n)
{
for(j=0;j<n;j++)
if(a[j]>=a[i])
{
b=a[i];
a[i]=a[j];
a[j]=b;
}
i++;
}
System.out.println(getName()+"the result is:");
for(j=0;j<n;j++)
{
System.out.print(" "+a[j]);
}
System.out.println(getName()+"insert end\n");
}
}
class Threadmaopao extends Thread
{
private int i=0,j=0,n=8;
int b;
int a[];
public Threadmaopao(int a1[],int n)
{
this.a=a1;
this.n=n;
}
public void run()
{
System.out.println(getName()+"maopao:");
for(i=0;i<n;i++)
{
for(j=1;j<n-i;j++)
{
if(a[j-1]>=a[j])
{
b=a[j-1];
a[j-1]=a[j];
a[j]=b;
}
}
}
System.out.println(getName()+"the result is:");
for(j=0;j<n;j++)
{
System.out.print(" "+a[j]);
}
System.out.println(getName()+"maopao end\n");
}
}结果:若结果无法显示请联系站长QQ752018766