Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: basic java problem concerning order of operations

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default basic java problem concerning order of operations

    Hello Everyone,

    I am new to Java programming and I am having a small problem with a java program concerning order of operations. The problem is as follow

    Write a code that declares variables for s0 with a value of 12.0, v0 with a value of 3.5, a with a value of 9.8, and t with a value of 10, for the for this equation.

    s=so + vo t + 1/2 at^2

    and then write the code to compute s on the basis of these values. At the end of your code, print the value of your variable s to the console.

    So Here is my code so far. the problem I seem to be having is at the end of the problem where I have to multiply a and t and then square it.

    Also print statement does not seem to work either. Any advice on how to fix this I would appreciate it.
     
    //declare variables
    double so;
    double vo;
    double a;
    double t;
    double s;
     
    //compute*s
    so = 12.0;
    vo = 3.5;
    a = 9.8;
    t = 10;
    s=(so) +(vot) +.05 a*t*t;
    //print results
    System.out.println("s");
    Last edited by Williamscn; September 18th, 2014 at 02:01 PM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: basic java problem concerning order of operations

    Can you edit your post to use the highlight tags and to post your code as an MCVE?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: basic java problem concerning order of operations

    Thank KevinWorkman,

    I edit my code to make it more readable. Although I could not find the ability of using highlight tags. I hope this helps.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: basic java problem concerning order of operations

    Can you post an MCVE instead of an incomplete snippet? What is the value of vot? What is this line supposed to do, not that it is not valid syntax:

    s=(so) +(vot) +.05 a*t*t;
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: basic java problem concerning order of operations

    I could not find the ability of using highlight tags.
    Here is how to wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Sep 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: basic java problem concerning order of operations

    I posted the values of each variable in the upper part of the code. What I am trying to do is write a math formula that solves for S.

    s=so + vo t + 1/2 at^2

    So I wrote my code in this format s=(so) +(vot) +.05 a*t*t;

    I have read the MCVE and to me my post does not seem long. I have tried to explain my problem in the top of my post and posted what I am declaring and the order of Operations I am trying to do in my code. So I am a little confused when you say post in MCVE and not a incomplete snippet.

    --- Update ---

    Thanks Norm.

    I edit my code to include the code tags.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: basic java problem concerning order of operations

    It would help if you would copy the full text of the error messages you get from the java compiler and paste them here.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: basic java problem concerning order of operations

    From your first post:

    s=(so) +(vot) +.05 a*t*t;

    You're missing some operators:

    "vot" should be "vo * t"
    ".05 a" should be ".05 * a"

  9. #9
    Junior Member
    Join Date
    Sep 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: basic java problem concerning order of operations

    Ok I find my mistake it was a simple matter of having the decimal place in the wrong place. I should have had 0.5 instead of .05.

    Thank you everyone for your help.

Similar Threads

  1. [SOLVED] Basic Java Problem
    By digitalsystems in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 29th, 2013, 12:49 PM
  2. Implementing basic operations on sets using Array Lists
    By Bucs1992 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 18th, 2012, 03:53 PM
  3. Counting basic operations in this Selection Sort
    By Keiran in forum Algorithms & Recursion
    Replies: 2
    Last Post: February 1st, 2012, 07:16 PM
  4. RPN Help Please! (Order of Operations)
    By yuvalb in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 30th, 2011, 10:53 AM
  5. Implementing order of operations for a Java calculator.
    By mjpam in forum Java Theory & Questions
    Replies: 2
    Last Post: May 15th, 2011, 06:11 PM