Swap array element in java in accending order -
i'm trying swap array in ascending order somewhere i'm going wrong. i'm taking input using
int n = integer.parse.int(args[0]);
but isn't working. below total code.
package tech; import java.util.*; import java.io.*; public class techgig { public static int ta[]={1,12,5,111,200,1000,10,9,6,7,4}; public static void main(string[] args) { // todo code application logic here system.out.println("amount mark has:"); int rs=50;//integer.parseint(args[0]); //int a=0; system.out.println(rs); // for(int k=0;k<ta.length;k++) //system.out.print("\t"+ ta); int min,temp; for(int i=0;i<ta.length;i++) { min=i; // system.out.print("\t"+ ta[i]); for( int j=i+1;j<ta.length;j++) { if(ta[i]<ta[min]) { temp=ta[i]; ta[i]=ta[min]; ta[min]=temp; } // system.out.print("\t"+ ta[i]); } } for(int k=0;k<ta.length;k++) { system.out.print("\t"+ ta[k]); } } }
you should replace variable i j here:
if(ta[i]<ta[min]) { temp=ta[i]; ta[i]=ta[min]; ta[min]=temp; }
java arrays
No comments:
Post a Comment