The following code correctly reads values entered by the use…
The following code correctly reads values entered by the user and calculates their product in an accumulating fashion until a particular sentinel value of 0 is encountered. It will avoid multiplying the product by the sentinel value of 0 by mistake. Assume console is a properly declared Scanner object that can read input from the console window.product = 1; System.out.print (“Enter a value:”); value = console.nextInt(); while (value != 0){ System.out.print (“Enter another value (0 to stop):”); value = console.nextInt(); product *= value;} System.out.println (“Product: ” + product);