Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35998

Re: COMPUTER PROJECT

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: COMPUTER PROJECT
Date 2016-11-30 08:38 -0500
Organization A noiseless patient Spider
Message-ID <o1mkmt$997$1@dont-email.me> (permalink)
References <cb8d4dc5-d021-4fe4-ae28-d29c43f46372@googlegroups.com>

Show all headers | View raw


On 11/30/2016 12:47 AM, naarayana.kumar@gmail.com wrote:
> import java.io.*;
> class Account1
> [...]

     Is this the *exact* program you are running?  I notice, for example,
that it has no `main' method, which is the method Java calls to start a
program.  (It is possible to run a program in other ways, but unusual.)

> In this program if i enter wrong value it doesnt say ERROR BUT I PUT CORRECT STATEMENT it says error.Please help.

     It would be helpful to know what "wrong value" and what "CORRECT
STATEMENT" you entered.  Without knowing that, all I can do is guess
at what is going on.

     Here's a guess at one of the problems.  In this fragment:

 >         String aa=y.readLine();
 >         int l=aa.length();
 >         for(int i=0;i<l;i++)
 >         {
 >             char ch=aa.charAt(i);
 >            int p=(int)ch;
 >             while(p<67 ||p>122)
 >             {
 >                 System.out.println("Error please retype");
 >                 System.out.println("Enter your name");
 >                 aa=y.readLine();
 >             }
 >         }

... consider what happens if the user entered "NAARAYANA" at the first
`readLine' call.  The `for' loop inspects the entered characters, one by
one.  The 'N' gives `p' the value 78, so the `while' loop is skipped.
Then the 'A' sets `p' to 65, which is less than 67, so the program goes
into the `while' loop.  Inside, it outputs "Error please retype" and
"Enter your name", then reads another line.  What is the value of `p'
at this point?  It is still 65, so the `while' loop executes again:
It outputs "Error please retype" and "Enter your name" and reads a
third line.  And since `p' is still 65, the loop executes yet again ...
If the `while' ever executes at all, it will keep on executing forever
no matter what you enter, until you pull the plug.

     You will learn (I'm surprised that you have not already learned)
that there are less error-prone ways to write the numerical codes for
'C' and 'z' than 67 and 122.  You could instead have written

	char ch = aa.charAt(i);
	while (ch < 'C' || ch > 'z')

... if that was truly your intent -- although I have no idea why you
reject names containing 'A' and 'B' while accepting some others with
obvious non-letters; it seems "Cr[_a_]zy^" to me, but ...

     I have not studied the rest of your code, in part because of the
strong suspicion that what you have shown is *not* actually your code
but some kind of paraphrase.  Even without study, though, I'd bet that
the problem I describe is only one of several.  If you need further
help with additional problems, please post the *exact* code you run,
and show *exactly* what you entered and *exactly* the output you got --
no "something like" or "sort of," but *exact*.

-- 
esosman@comcast-dot-net.invalid
"Nobody ever went broke underestimating the intelligence of the
American public." -- HLM (paraphrased)

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

COMPUTER PROJECT naarayana.kumar@gmail.com - 2016-11-29 21:47 -0800
  Re: COMPUTER PROJECT Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-11-30 08:38 -0500
    Re: COMPUTER PROJECT lewbloch@gmail.com - 2016-12-01 13:30 -0800
  Re: COMPUTER PROJECT Andreas Leitgeb <avl@logic.at> - 2016-11-30 14:30 +0000
  Re: COMPUTER PROJECT Rhino <no_offline_contact@example.com> - 2016-11-30 11:26 -0500
    Re: COMPUTER PROJECT Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-11-30 12:03 -0500
      Re: COMPUTER PROJECT Eric Douglas <e.d.programmer@gmail.com> - 2016-11-30 10:04 -0800

csiph-web