Question: The program segment below are codes for bubble sort. How does the program sort the values that are entered by the user? Ascending or Descending?

The program segment below are codes for bubble sort. How does the program sort the values that are entered by the user? Ascending or Descending?

Scanner sc=new Scanner(System.in);

int[]numbers=new int[5];

inti,temp,pass=1;

for(i=0;i

System.out.print("Enter value for index["+i+"] here --> ");

numbers[i]=sc.nextInt( );

}

while(pass

for(i=0;i<(numbers.length-pass);i++){

if(numbers[i]

temp=numbers[i];

numbers[i]=numbers[i+1];

numbers[i+1]=temp;

}

}

pass++;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!