This code, why it doesn't give the correct output?
The code is supposed to sort the values stored in a vector in ascending
order.
For example, we have a vector "4,2,3,1", and we want the output to be in
order "1,2,3,4".
Also, do you have any other way of doing this?
How do we get the correct output??
public class Tester{
public static void main(String[] args){
int temp=0;
int[] v={4,2,3,1};
System.out.println(v);
for (int i=1; i<v.length;i++)
{
for (int j=1; j<v.length-i;j++)
{
if (v[j+1]>v[j])
temp=v[j+1];
v[j+1]=v[j];
v[j]=temp;
}
}
System.out.println(v);
}
}