-
Printing total out
When i enter in numbers into the client side of the application I want to have them appear on the server side as i enter them and then when i enter in "End" i want the program to tell me on the client and the server side what the total is. The code that i have at the minute is
Code:
do{
System.out.println("Enter a Number: "+i);
number= br.readLine( );
if (number.equalsIgnoreCase("End"))
{
System.out.println("TOTAL " + numberBack);
System.out.println("Session Over ");
helper.done();
}//end if
numberBack = helper.getnumber(number);
i++;
}
while (!number.equalsIgnoreCase("End"));
helper.done();
} // end try
catch (Exception ex) {
ex.printStackTrace();
} //end catch
Does anyone know how to do this. I can do it for a specific number of numbers but i want to be able to do it for any amount of numbers
-
I'm not exactly clear what you expecting. Can't figure out some variables, methods and so. But the logic you are expecting is this.
Code:
import java.util.Scanner;
public class denisdoherty {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int i = 1;
int total = 0;
boolean stat = true;
do {
System.out.println("Enter the number " + i + " ");
String str = input.nextLine();
if(!str.equalsIgnoreCase("End")) {
int value = Integer.parseInt(str);
total += value;
}
else {
stat = false;
System.out.println("TOTAL " + total);
System.out.println("Session Over ");
}
i++;
}while(stat);
}
}