I can't get it to print outside of the loop?
package com.codegym.task.task05.task0529;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
Console-based piggy bank
*/
public class Solution {
public int total;
public static void main(String[] args){ // throws Exception {
//write your code here
try{
//int total=0;
String s = "int";
int i;
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
while (true)
{
s = buffer.readLine();
i = Integer.parseInt(s);
total = total + i;
//System.out.print(s + " " );
//System.out.print(i + " ");
//if (s.equals("sum")) { System.out.println(total); }
if (s.equals("sum")) { System.out.println(total); break; }
}
System.out.println(total);
/*
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String inS=null;
//int inI=0;
int total=0;
while ( buffer.readLine() != null )
{
inS = buffer.readLine();
if (inS.equals("sum")) {
break;
}
else {
//inI = Integer.parseInt(inS);
total += Integer.parseInt(inS);
//System.out.print(inI + " " + inS + " " + total + " ");
}
System.out.println(total);
//inI = Integer.parseInt(inS);
//total += inI;
}*/
System.out.println(total);
}catch(Exception e){}
}
}