Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Variable confusion(confusion with calling variables)
Variable confusion [message #1706715] Sat, 29 August 2015 04:21 Go to next message
Brandon Finley is currently offline Brandon FinleyFriend
Messages: 3
Registered: August 2015
Junior Member
Hello. I am a beginner programmer trying to create a simple adding calculator. I start by asking the user two numeric values and then automatically adding them together (fairly simple). However, I am running into problems calling the variable that adds the two numbers together and outputting the answer into the system.println, any help is appreciated.

-----------------------Code------------------------------------------------------------------------------
import java.io.*;

public class Calculator {

public static void main(String[] args) {
String s1 = getInput("Enter a numeric value: ");
String s2 = getInput("Enter a numeric value: ");

Double d1 = Double.parseDouble(s1);
Double d2 = Double.parseDouble(s2);
Double result = d1 + d2;

System.out.println("The answer is " result);

}

private static String getInput(String prompt) {
BufferedReader stdin = new BufferedReader(
new InputStreamReader(System.in));

System.out.print(prompt);
System.out.flush();

try {
return stdin.readLine();
} catch (Exception e) {
return "Error: " + e.getMessage();
}
}

}
Re: Variable confusion [message #1706762 is a reply to message #1706715] Sun, 30 August 2015 16:22 Go to previous message
Erick Hagstrom is currently offline Erick HagstromFriend
Messages: 107
Registered: April 2014
Location: USA
Senior Member
This forum is for Eclipse questions. You could perhaps try stackoverflow.com for help with Java. When you get there, please be sure you're more specific about the problem that you're having, what you expect the code to do, and what it actually does.
Previous Topic:Finding dependencies of a package or file
Next Topic:Getting a Project From Github to Eclipse
Goto Forum:
  


Current Time: Mon Nov 11 17:28:03 GMT 2024

Powered by FUDForum. Page generated in 0.03783 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top