Hello, I am new to java and was trying to write a program to add two numbers which the user provides at runtime, but I cant find the command to accept data from the user. Can some one help me? Thanks, - Rahul
Hello Rahul, Below is a simple command-line program that will accept 2 inputs, then attempts to add them. If the input is non-numeric, a NumberFormatException is thrown. Hope it helps to clear up the concept for you.
[ June 01, 2002: Message edited by: Dirk Schreckmann ]
Hello Dick, I tried out the code given below, and it has worked. This was mostly from your second code example ( because I wanted a program that prompts the user for data, and this could be a base for later programs which would be based upon interaction with the user). But the code seems a bit too long for such a simple program, and I am not very well versed yet with streams or exceptions. What I was really looking for was the java equivalent of the C++ command : cin<< variable ; Anyway, thanks a lot for your help. - Rahul P.S. What does SCJP2 & SCWCD stand for? (I can guess that SCJP stands for Sun Certified Java Programmer but what is the 2 for?)
[ June 01, 2002: Message edited by: Rahul Dasgupta ] [ June 02, 2002: Message edited by: Dirk Schreckmann ]
posted 16 years ago
Originally posted by Rahul Dasgupta: Hello Dick,
Sure, call me names, then have the nerve to ask for more advice! I've never...
SCJP2 more or less stands for Sun Certified Programmer for the Java 2 Platform. Some may argue that it actually stands for Sun Certified Java Professional, but I think Sun more frequently uses the previous phrase. SCWCD stands for Sun Certified Web Component Developer.
...the code seems a bit too long for such a simple program... The code does indeed not need to be quite so long. Notice that a few parts are more or less exactly repeated. This repetition isn't necessary. One hint for simplification: Do you really need two BufferedReaders? Or could you just reuse the original one? In that vein, is it possible to reuse other parts of the code as well? Getting any ideas?