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)
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]);
}
}
Comments
Leave a comment