With example below do not understand why console reads number but will not read String input
for(int i=0; i < 5; i++) {
try(Scanner keyboardInput = new Scanner (System.in)){
System.out.print("Enter five numbers: ");
int num = keyboardInput.nextInt();
System.out.println("Do you want to add this number to num(yes/no)?");
String result = keyboardInput.nextLine();
if(result == "yes") {
total = num + total;
System.out.print("The total is: " + total);
}}}
After I enter the value as required, current script does not let me enter String value. I have tried splitting sections of script by moving them to different braces but this just then does not identify variables that have been locally defined and even when I try to re-define variable code does not work.
If code completed in sections, the part that requires user entry of values works just fine. I an expecting to be able to have nextInt & nextLine user inputs to work together in same script.