I have a bookstore application, but I cannot show the maximum and minimum and maximum price of the book, in the end the program. Please see my codes below.

    import java.util.*;
    public class Book{
        public static void main(String args[]){

            int numOfBook;
            double totalCost = 0;
            String expBookTitle = "";
            double expBookPrice = 0;
            String cheapBookTitle = "";
            double cheapBookPrice = 0;

            Scanner input = new Scanner(System.in);
            System.out.println("Welcome to SAJID's Book Shop");

            System.out.print("How many book would you like to store: ");
            numOfBook = input.nextInt();

            String[] book = new String[numOfBook];
            double[] bookPrice = new double[numOfBook];

            for(int i=0;i<book.length;i++)
                System.out.print("Please enter book name: ");
                book[i] = input.next();

                System.out.print("Please enter book price: ");
                bookPrice[i] = input.nextDouble();

                totalCost += bookPrice[i];

                if(bookPrice[i] == expBookPrice)
                    expBookPrice = bookPrice[i];
                    expBookTitle = book[i];

                System.out.println("Expensive book price: " + expBookPrice);
                System.out.println("Expensive book title: " + expBookTitle);

                if(bookPrice[i] <= expBookPrice)
                    cheapBookPrice = bookPrice[i];
                    cheapBookTitle = book[i];

                System.out.println("Cheap book price: " + cheapBookPrice);
                System.out.println("Cheap book title: " + cheapBookTitle);




Line 36 - you want to know if the price is greater than the highest you have found so far (cf line 45).
Then look at the initialisation of cheapBookPrice - if it starts at 0 will you ever find a cheaper one in your data?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.