//冒泡排序,传递参数的问题class bubblesort{
void bubble(int [] a){
int n=a.length;
int temp;
for(int i=n-1;i>0;i--){
for(int j=0;j<=i-1;j++){
if(a[j]>a[j+1]){ //从小到大排序
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
}
}class e24{
public static void main(String args[]){
int[] m={3,45,8,1,98,37,80,9,6};
System.out.println("before dubble_sort::");
System.out.print("m[");
for(int i=0;i<m.length;i++){
System.out.print(m[i]+" ");
}
System.out.println("]");
bubblesort ob=new bubblesort();
ob.bubblesort(m);
System.out.println("after dubble_sort:");
System.out.print("m[");
for(int i=0;i<m.length;i++){
System.out.print(m[i]+" ");
}
System.out.println("]");
}
}//冒泡排序,传递参数的问题,请大家指教
void bubble(int [] a){
int n=a.length;
int temp;
for(int i=n-1;i>0;i--){
for(int j=0;j<=i-1;j++){
if(a[j]>a[j+1]){ //从小到大排序
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
}
}class e24{
public static void main(String args[]){
int[] m={3,45,8,1,98,37,80,9,6};
System.out.println("before dubble_sort::");
System.out.print("m[");
for(int i=0;i<m.length;i++){
System.out.print(m[i]+" ");
}
System.out.println("]");
bubblesort ob=new bubblesort();
ob.bubblesort(m);
System.out.println("after dubble_sort:");
System.out.print("m[");
for(int i=0;i<m.length;i++){
System.out.print(m[i]+" ");
}
System.out.println("]");
}
}//冒泡排序,传递参数的问题,请大家指教
System.out.print("m[");
for(int i=0;i<m.length;i++){
System.out.print(m[i]+" ");
}
System.out.println("]");
bubblesort ob=new bubblesort();
ob.bubble(m);//修改处改了上面一下就好了,你在那个地方的方法名写错了
///////////////////////////
class bubblesort{
void bubble(int [] a){
int n=a.length;
int temp;
for(int i=n-1;i>0;i--){
for(int j=0;j<=i-1;j++){
if(a[j]>a[j+1]){ //从小到大排序
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
}
}class e24{
public static void main(String args[]){
int[] m={3,45,8,1,98,37,80,9,6};
System.out.println("before dubble_sort::");
System.out.print("m[");
for(int i=0;i<m.length;i++){
System.out.print(m[i]+" ");
}
System.out.println("]");
bubblesort ob = new bubblesort();
ob.bubble(m);
System.out.println("after dubble_sort:");
System.out.print("m[");
for(int i=0;i<m.length;i++){
System.out.print(m[i]+" ");
}
System.out.println("]");
}
}-------------------------------------------------------------------------------------
自己仔细检查一下了。
method调用错误