need help on a simple JAVA program

Dear all
 
    I need a simple program that can read two input numbers(type:Double), add each other and print out. I looked many books, but they all focus on Applet or web programming, can't find any sample that I can use. Please help me on this program. Thank you.

CC
puppyhuangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bobbit31Commented:
import java.io.*;

public class AddDoubles {
   public static void main(String[] args) {
       double d1, d2;

       BufferedReader in = null;

       try {
            in = new BufferedReader(new InputStreamReader(System.in));
            String strD1, strD2;

            System.out.print("Enter number 1: ");
            strD1 = in.readLine();
            System.out.print("Enter number 2: ");
            strD2 = in.readLine();

            d1 = Double.parseDouble(strD1);
            d2 = Double.parseDouble(strD2);

            System.out.println (d1 + d2);
        } catch (Exception e) {
             e.printStackTrace();
        } finally {
             if (in != null) {
                  try {
                       in.close();
                  } catch (IOException ignored) {}
             }
        }
     }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
That's somebody's homework fixed then...
0
bobbit31Commented:
wow, if that's homework, than our school system is going downhill... sorry, i didn't interpret it as a homework... mods repremand me if you want... but if you look at my profile, i definitely do not make it a habit to answer blatant homework q's
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

CEHJCommented:
Don't worry bobbit - it's easy to forget sometimes ;-)
0
puppyhuangAuthor Commented:
Thank you very much. You gave me a very good sample and I made another one for my homework.  Thank you for your help.

CC
0
jwentingCommented:
the school system IS going downhill, dumb people are easier to manipulate so they'll believe the lies in the election campaigns more easily :-)
But remember that classes have to start simple with their lessons, you don't know how far along in his Java classes this questioner is...
0
CEHJCommented:
QED bobbit ;-)

It's certainly much better than the habit of giving beginners ludicrously ambitious tasks, which happens frequently.
0
CleanupPingCommented:
puppyhuang:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
bobbit31Commented:
recommendation: points to bobbit31
0
tomboshellCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept bobbit31's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thomas Boshell
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.