int[] array (sort lowest to highest)

后端 未结 11 1571
悲哀的现实
悲哀的现实 2020-12-01 13:32

So I am not sure why this is becoming so hard for me, but I need to sort high to low and low to high.

For high to low I have:

int a, b;
int temp;
int         


        
11条回答
  •  时光说笑
    2020-12-01 13:52

    Let me know if this works:

    public class prog1 {
        public static void main (String args[]){
            int a[] = {1,22,5,16,7,9,12,16,18,30};
    
            for(int b=0; b<=a.length;b++){
                for(int c=0; c<=a.length-2;c++){
                    if(a[c]>a[c+1]){
    
                        int temp=0;
                        temp=a[c];
    
                        a[c]=a[c+1];
                        a[c+1]=temp;
                    }
                }
    
            }
            for(int b=0;b

提交回复
热议问题