[Solved] maximum from user input + string


You just need to keep both the maximum price and the name of the product with that maximum price. For example,

Product[] products = // your products.
Product mostExpensiveProduct = product[0];

for (Product product : products) {
  if (product.getPrice() > mostExpensiveProduct.getPrice()) {
    mostExpensiveProduct = product;
  }
}

System.out.println("Most expensive product is " + mostExpensiveProduct.getName() + " with price " + mostExpensiveProduct.getPrice());

solved maximum from user input + string