Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Variable confusion(confusion with calling variables)
Variable confusion [message #1706715] Sat, 29 August 2015 00:21 Go to next message
Eclipse UserFriend
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 12:22 Go to previous message
Eclipse UserFriend
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: Sun Apr 27 20:13:01 EDT 2025

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

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

Back to the top