0

How do I get this to ignore negative number and terminate when the number 0 is entered?
Please HELP

public void productTokenizer()throws IOException
{
        System.out.println("Enter numbers to accumlulate their total.");//Prompt user to enter data
        //System.out.println("Zero and all negative numbers will Exit the Program:");

         double sum = 0; int num = 0;

        BufferedReader br = new BufferedReader(
        new InputStreamReader(System.in));
        String input = br.readLine();

        StringTokenizer tokenizer = new StringTokenizer(input);


        while (tokenizer.hasMoreTokens())
        {



                        String token = tokenizer.nextToken();

            double x = Double.parseDouble(token);
            sum = sum + x;
            num++;
        }

                 System.out.println("The sum is: " + sum);

    }
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Samudricka
0

i think it can be done after converting into double please ckeck with an if condition if(x>0) then i think you can access only positive numbers

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.