Results 1 to 2 of 2
  1. #1
    denisdoherty is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default 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

    Java 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

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

    Java 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);
        }
    
    }

Similar Threads

  1. Problem after Printing GUI.
    By coldblood22 in forum AWT / Swing
    Replies: 1
    Last Post: 04-05-2008, 02:43 PM
  2. Printing (no dialog)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-04-2008, 09:36 AM
  3. Printing using java
    By ramachandran in forum Advanced Java
    Replies: 1
    Last Post: 01-05-2008, 10:16 AM
  4. printing problem
    By ntpl in forum AWT / Swing
    Replies: 0
    Last Post: 11-27-2007, 11:20 AM
  5. [Java Printing]
    By remnahush in forum Advanced Java
    Replies: 1
    Last Post: 11-08-2007, 03:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •