Results 1 to 7 of 7
  1. #1
    Aimforthehead is offline Member
    Join Date
    Sep 2011
    Posts
    45
    Rep Power
    0

    Default 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
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default 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!

  3. #3
    Aimforthehead is offline Member
    Join Date
    Sep 2011
    Posts
    45
    Rep Power
    0

    Default 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

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: New to Java, need help

    Quote Originally Posted by Aimforthehead View Post
    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
    As expected.

    This forum is not a great substitute for a textbook or tutorial and you really need to hit the basic tutorials to move forward. Read up on how to declare and use variables first.

  5. #5
    Aimforthehead is offline Member
    Join Date
    Sep 2011
    Posts
    45
    Rep Power
    0

    Default 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.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: New to Java, need help

    Quote Originally Posted by Aimforthehead View Post
    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.
    My concern though is if you don't know how to declare a variable, you've got some gaps that need to be filled and more than just on the specifics of variable handling. This is best solved by study.

  7. #7
    Aimforthehead is offline Member
    Join Date
    Sep 2011
    Posts
    45
    Rep Power
    0

    Default Re: New to Java, need help

    I understand, I will learn patience from this :D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •