View the step-by-step solution to:

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?


Scanner sc=new Scanner(System.in);

int[]numbers=new int[5];

inti,temp,pass=1;

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

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

numbers[i]=sc.nextInt( );

}

while(pass<numbers.length){

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

if(numbers[i]<numbers[i+1]){

temp=numbers[i];

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

numbers[i+1]=temp;

    }

}

pass++;

}     

Top Answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question