0
how to get in Ascending order
public class Ascending { public static void main(String args[]) { int a[]={96,55,29,22,48,76,33,88,12,99}; int temp=0,j=0; for(int i=0; i<a.length; i++) { for( j=i+1; j<a.length; j++) { System.out.println("i="+i+" j="+j+" a[i]="+a[i]+" a[j]="+a[j]); if(a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } System.out.println(" "); } for(int i=0; i<a.length; i++) { System.out.print(temp); } } }
2 Respostas
+ 4
for(int i=0; i<a.length; i++)
{
System.out.print(a[i]+" ");
}
Or
you can use inbuilt method :
System.out.println(java.util.Arrays.toString(a));
You are printing temp variable value in loop....
0
You can implement bobble sort algorithm just google it there are all sorts of sorting algorithms which can be used in different contexes. Learning these would also help you in the long run.