Hello,
I want to solve this task via using Scanner, however it is not catching the exception i.e. input of the string 'sum' properly.
Any suggestions?
package com.codegym.task.task05.task0529;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
/*
Console-based piggy bank
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
Scanner unos=new Scanner(System.in);
int suma=0;
while(true) {
if (unos.hasNextLine()) {
String tekstsuma=unos.nextLine();
if (tekstsuma.equals("sum")) {
System.out.println(suma);
return;}
}
int broj=unos.nextInt();
suma+=broj;
}}}