?
Solved

need help on a simple JAVA program

Posted on 2003-02-22
11
Medium Priority
?
163 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:puppyhuang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 100 total points
ID: 8000287
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8000569
That's somebody's homework fixed then...
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8000604
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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 86

Expert Comment

by:CEHJ
ID: 8000636
Don't worry bobbit - it's easy to forget sometimes ;-)
0
 

Author Comment

by:puppyhuang
ID: 8001861
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
 
LVL 6

Expert Comment

by:jwenting
ID: 8002124
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8003217
QED bobbit ;-)

It's certainly much better than the habit of giving beginners ludicrously ambitious tasks, which happens frequently.
0
 

Expert Comment

by:CleanupPing
ID: 9059144
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 9072061
recommendation: points to bobbit31
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 9582325
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question