0
public class DoubleArray
{
    static Console c;           // The output console
    static final int total = 20;
    String[] numStr = new String [total];
    static double numDbl;
    static String stop = "";

    public void getAndStoreInput ()
    {
        int count = 0;
        do
        {
            c.print ("Enter number" + (count + 1));
            c.print (": ");

            while ((numStr [count] = c.readLine ()) != stop)
            {
                try
                {
                    numDbl = Double.parseDouble (numStr [count]);
                    count++;
                    break;

                }

                catch (NumberFormatException e)
                {

                    new Message ("Invalid. Please Try Again");
                }

            }

        }
        while (count < total);
    }

Isn't my code supposed to stop getting input when the user just press enter without any characters?

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by stultuske
0

nope ...
you can find the value of 'Enter' online if you want, but it would be easier to just compare to a fixed value to stop (and no, "" is not the value for enter)

next to that: != is not the way you check for not-equality between objects, you would have to use (!a.equals(b))

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.