Answer to Question #291582 in Java | JSP | JSF for botans

Question #291582

 Display the Most Expensive Book

Displays the most expensive book from the list. For example, consider the following list of books:


Introduction to AI 1200.00 450

Reinforcement Learning 1300.99 1000

Deep Learning: Practical 1575.60 850

When we select the option, it displays the following output:

Deep Learning: Practical 1575.60 850


You may use the following header for this method:

static void showMostExpensive(String[][] books, int currentSize)


1
Expert's answer
2022-01-28T12:52:47-0500
public class Main {
    static void showMostExpensive(String[][] books, int currentSize) {
        int maxIndex = 0;
        for (int i = 0; i < currentSize; i++) {
            if (Double.parseDouble(books[maxIndex][1]) < Double.parseDouble(books[i][1])) {
                maxIndex = i;
            }
        }
        System.out.println(books[maxIndex][0] + " " + books[maxIndex][1] + " " + books[maxIndex][2]);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS