有人知道我錯哪里了嗎?拜托指正
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? HelloWorld h=new HelloWorld();
? ? ? ? ?int[] a={23,67,89,65,98};
? ? ? ? int[] b=h.abslot(a);
? ? ? ? for(int i=0;i<b.length;i++){
? ? ? ? ? ? ? System.out.print(b[0]+" "+b[1]+" "+b[2]+" ");
? ? ? ? ? ? ??
? ? ? ? }
? ? ? ? }
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ??
? ? public int[] abslot(int[] a){
? ? ? ?
? ? ? ? for(int i=1;i<a.length;i++){
? ? ? ? ? ? for(int j=0;j<length-i;j++){
? ? ? ? ? ? ? ? if(a[j]<a[j+1]){
? ? ? ? ? ? ? ? ? ? int temp=a[j];
? ? ? ? ? ? ? ? ? ? a[j]=a[j+1];
? ? ? ? ? ? ? ? ? ? a[j+1]=temp;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? for(int i=0;i<length;i++){
? ? ? ? ? ? if(a[i]>=0&&a[i]<=100){
? ? ? ? ? ? ? ? while(i==2){
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return a;
? ? }
? ??
}
2019-08-11
for(int i =0;i<a.length-1;i++)???????????????????? {if (a[i]<a[i+1])int temp=a[i];a[i]=a[i+1];a[i+1]=temp;??????? }java util包中Arrays類里面有排序函數(shù)sort( )
2019-08-11
你的排序出現(xiàn)問題了不用雙重循環(huán)