(Solved) : Wrong Following Code Piece Code Incorrectly Attempts Find Largest Value Queue Integers Wou Q42705708 . . .

  1. What is wrong with the following code? This piece of codeincorrectly attempts to find the largest value in a queue ofintegers. How would you fix it? You will need to write a class withthe main(String[] args) {….} method to test the following piece ofcode, find the problem, and fix it.

          intlargest = q.remove(); //assume the first one is the largest.

                for(inti=0; i <q.size(); i++){

                       largest =Math.max(largest,q.remove());

                }

There are many ways to find the maxi value from a queue list.For this problem, you are not allowed to use any collectionutilities; you will have to use the Math.max( largest, q.remove( ))method and you cannot modify the original queue contents. Forexample, with my queue list (1, 2, 3, 99, -4, 6), the resultsshould look like the following.

Orginal list

[1, 2, 3, 99, -4, 6]

largest = 99

After finding maxi, the list is

[1, 2, 3, 99, -4, 6]

Expert Answer


Answer to What is wrong with the following code? This piece of code incorrectly attempts to find the largest value in a queue of …

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?