What is causing my program to skip the first iteration of my while loop here?:
import java.util.Scanner;
public class myfun {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int totalNumbers;
int product = 0;
int count = 0;
int sum = 0;
String choice = "choice";
System.out.print("You can add up to ten numbers.\n");
while(! choice.equalsIgnoreCase("stop")){
System.out.print("Would you like to add or multiply? (Enter stop to be done)");
choice = scan.nextLine();
if (choice.equalsIgnoreCase("multiply")) {
product = 0;
System.out.print("How many numbers would you like to multiply?");
totalNumbers = scan.nextInt();
count = 0;
System.out.print("Please enter " + totalNumbers +" numbers.");
product +=scan.nextInt();
count++;
while (count < totalNumbers) {
product *= scan.nextInt();
count++;
}
System.out.println("The product is " + product);
}
else if (choice.equalsIgnoreCase("add")) {
sum = 0;
System.out.print("How many numbers would you like to add?");
totalNumbers = scan.nextInt();
count = 0;
System.out.print("Please enter " + totalNumbers +" numbers.");
sum +=scan.nextInt();
count++;
while (count < totalNumbers) {
sum += scan.nextInt();
count++;
}
System.out.println("The sum is " + sum);
}
}
System.out.print("Come again!");
scan.close();
}
}
here's an example output
You can add up to ten numbers. Would you like to add or multiply? (Enter stop to be done) add How many numbers would you like to add? 2 Please enter 2 numbers.2 2 The sum is 4 Would you like to add or multiply? (Enter stop to be done)Would you like to add or multiply? (Enter stop to be done)