Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » variable confusion(Question about calling a variable)
variable confusion [message #1706714] Sat, 29 August 2015 04:10 Go to next message
Brandon Finley is currently offline Brandon FinleyFriend
Messages: 3
Registered: August 2015
Junior Member
Hello. I am a new java programmer using Eclipse. I am following a tutorial off of lynda.com when I came across an error that I am not sure how to fix.

I am trying to create a simple calculator that receives two numeric values from the user and adds them together. My current code looks like this:
--------------------------------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 d3 = d1 + d2;

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

}

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();
}
}
}
--------------------------------------------code---------------------------------------------------------

I believe the problem has something to do with calling the "d3" variable that is adding the two numbers together. Let me know what you think and if you can help. Thanks!
Re: variable confusion [message #1706735 is a reply to message #1706714] Sat, 29 August 2015 12:32 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Without telling us the actual error message, I can only point out that your call to System.out.println() is not valid syntax.

This is primarily a forum for people encountering issues specifically with Eclipse, not really one aimed at covering questions about the supported languages themselves. You'd find a more appropriate audience at http://www.javaranch.com/ and their "Beginning Java" forum at http://www.coderanch.com/forums/f-33/java (assuming Lynda has no such outlet of their own).


_
Nitin Dahyabhai
Eclipse Web Tools Platform

[Updated on: Sat, 29 August 2015 12:32]

Report message to a moderator

Re: variable confusion [message #1706912 is a reply to message #1706735] Mon, 31 August 2015 18:44 Go to previous message
Brandon Finley is currently offline Brandon FinleyFriend
Messages: 3
Registered: August 2015
Junior Member
thanks for pointing me in the right direction.
Previous Topic:Eclipse MARS - CVS
Next Topic:[Resolved] Past forum discussions
Goto Forum:
  


Current Time: Wed Apr 24 14:55:24 GMT 2024

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

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

Back to the top