Results 1 to 7 of 7
Thread: New to Java, need help
- 09-05-2011, 10:58 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 45
- Rep Power
- 0
New to Java, need help
So, I'm having a hard time wrapping my head around all this programming business. I know how to write simple things like the HelloWorld program, but now we are getting into the int and double classes and I don't know how to write them out..
for example, it says..
double x = 2.5;
double y = -1.5;
int m = 18;
int n = 4;
and the first problem is
x + n * y - (x-n) * y
So how would I write this out as a program?
I'm not asking anyone to write the program out for me, but maybe an outline of where I would define the double's and int's, then where I'd write out the problem?
So far I have this, and I'm sure a lot of it is inaccurate but whatever....Thanks in advance!
/**
*
* @author *******
* B14 - 9/5/2011
* Math.java
*/
public class Math {
// Define the main method
public static void main(String[] args) {
double x = 2.5;
double y = -1.5;
int m = 18;
int n = 4;
System.out.println("x+n*y-(x+n)*y"); // Print line
}
}
-
Re: New to Java, need help
Suggestions:
- First calculate your result and put it into a double variable, then print out the result.
- You shouldn't use this forum as a substitute for your compiler since it is so easy for you to compile, check errors, revise and re-compile yourself, and I suggest that you do just this.
- If you are unclear about what error messages mean, please post the messages and your questions.
Next we'll work on code tags when posting code in the forum, but one thing at a time.
Best of luck!
- 09-05-2011, 11:11 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 45
- Rep Power
- 0
Re: New to Java, need help
I'm not sure what you mean by put it into a double variable, sorry, I'm not as competent on the subject as I'd hoped :P
I compiled and it simply printed out x+n*y-(x+n)*y
-
Re: New to Java, need help
- 09-05-2011, 11:32 PM #5
Member
- Join Date
- Sep 2011
- Posts
- 45
- Rep Power
- 0
Re: New to Java, need help
Oh, all I had to do was write it as
double x;
x = 2.5;
etc.
and get rid of the quotations around my input....
I know it's good to learn these things on your own and all, but I don't think it would have been all that harmful to let me know I was at least really close -_- Thanks for the time.
-
Re: New to Java, need help
- 09-05-2011, 11:37 PM #7
Member
- Join Date
- Sep 2011
- Posts
- 45
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks