Hello everyone!
I`ve been trying to solve this task for manny hours, but nothing came up to my head. I`ve been trying with simply while loop, without hasNextInt() and hasNextLine() ect. but nothing meets the second requirement. Pls help. I`d like to solve and understand this task. Thanks!
Proposing inputs of this task are: 14; 11; 19; 9; ENTER
package en.codegym.task.pro.task04.task0403;
import java.util.Scanner;
/*
Summation
*/
public class Solution {
public static void main(String[] args) {
Scanner keybord = new Scanner(System.in);
boolean isExit = (false);
int a = 0, b = 0, c = 0, d = 0,sum = 0;
while(!isExit)
{
if(keybord.hasNextInt())
{
a = keybord.nextInt();
b = keybord.nextInt();
c = keybord.nextInt();
d = keybord.nextInt();
sum = a; sum = sum + b; sum = sum + c; sum = sum + d;
}
else if(keybord.hasNextLine())
{
String password = keybord.nextLine();
isExit = password.equals("ENTER");
}
}
System.out.println(sum);
}
}