Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Urgent Help Nedded!!!

Options
  • 11-08-2004 11:33pm
    #1
    Registered Users Posts: 3,695 ✭✭✭


    hi,
    this is a java related question. i have to repeat this exam in college!!!

    int w=6, x=7, y=8, x=9, result;

    Compute the following results and show step by step how the result is achieved:

    result=w*y/x%z+7;

    heres what i got.
    result=6*8/7%9+7;
    result=48/7%9+7;
    result=6%9+7;
    result=3+7;
    result=10;

    is this answer correct


«1

Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    No. The operator precedence is correct, but the final answer is incorrent.


  • Registered Users Posts: 834 ✭✭✭fragile


    Your mistake is with the modulus operator, here some instructions..

    http://www.cs.umd.edu/~clin/MoreJava/Intro/expr-mod.html


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Whereas I was leaving it open for him to find the answer himself... Like a good programmer should learn to do, rather than have the solution handed on a silver platter.


  • Registered Users Posts: 834 ✭✭✭fragile


    Whereas I was leaving it open for him to find the answer himself... Like a good programmer should learn to do, rather than have the solution handed on a silver platter.

    I was trying to do the same, but with a thread title Urgent Help Nedded!!!, I thought that a little more help was called for


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    fragile,
    this makes no sense to me! can you please explain? i keep giong over and over it and i still keep getting 10 for the answer!!!


  • Advertisement
  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    Please Can Someone Help Me! I Have To Repeat This Exam Next Week And I Cant Afford To Spend Ages Looking For Answers!


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    Please Im In Need Of Some Urgent Help Here!!!!!!!!


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    You ran the Modulus operator the wrong way.

    9%6 == 3
    6%9 == ?


  • Registered Users Posts: 834 ✭✭✭fragile


    Galwaydude in all fairness this is only one potential question in your exam, did you read and understand the explanations in the link I posted? I have already told you that your mistake is with your understanding of how the modulus operator works.....come on you are 90% there, just re-read how the modulus operator works and try to figure it out...


    I dont mean to be cruel, if you are still stuck just reply and I will post up a full explanation, but you really should give it another genuine try


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    fragile 6%9 give a number less than 1. this cannot be correct according to the instructions in the link you gave me!! (the result is always greater than or equal to 0)


  • Advertisement
  • Registered Users Posts: 834 ✭✭✭fragile


    (the result is always greater than or equal to 0)

    So, if the result cant be less than 0 what is the remainder of 6%9? and remember this is not the same as 6/9..


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    fragile the remainder would be 0 is this correct because if it is that would mean the answer is 7 right?


  • Registered Users Posts: 834 ✭✭✭fragile


    PM sent


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    fragile i didnt get your pm!


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    fragile how about this

    int w=6, x=7, y=8, x=9, result;

    result=(w-y)/(x-z)+51%(x+5);

    i got result=3; for the answer!


  • Registered Users Posts: 2,243 ✭✭✭zoro


    10 % 2 = 0

    Why?
    Take 2 from 10 until you can't do it fully any more ...
    10 - 2 = 8
    8 - 2 = 6
    6 - 2 = 4
    4 - 2 = 0
    2 - 2 = 0
    0
    --> 10%2=0

    11 % 2 = ?
    11 - 2 = 9
    9 - 2 = 7
    7 - 2 = 5
    5 - 2 = 3
    3 - 2 = 1
    1 < 2 so stop here. Your MOD answer is 1 (your remainder)

    Try it like this so:
    15 % 8 = ?
    15 - 8 = 7
    7 < 8 so stop
    7 == your answer

    Does that help you to understand it?
    Daniel


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    thanks! i understand it now! do you know what this means?

    int w=6,x=7,y=8,z=9, result;

    result=(x>=y)?x-y:y-x;

    i do not understand it!!


  • Registered Users Posts: 834 ✭✭✭fragile


    thanks! i understand it now! do you know what this means?

    int w=6,x=7,y=8,z=9, result;

    result=(x>=y)?x-y:y-x;

    i do not understand it!!

    PM sent


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    fragile how about the pm i sent you? what do they mean??? Thanks for your help so far!!!!


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    what do these mean?

    int w=6,x=7,y=8,z=9, result;

    result=x*((y==8)?100:999);

    result=(--x*w++)/z++ - ++y;

    i do not understand them!!

    here's the answers i got! can someone please explain them in more detail?

    result=x*((y==8)?100:999);
    result=7*((8==8)?100:999);
    result=7*100;
    result=700;

    Ok, for the next one, if the operator is before the variable (--y) you calculate it straight away, if it is after the variable (x++) you ignore it (it does matter in loops, but not in these examples)

    result=(--x*w++)/z++ - ++y;
    result=(--7*6++)/9++ - ++8;
    result=(36)/9 - 9;
    result=4-9;
    result=-5;


  • Advertisement
  • Registered Users Posts: 2,243 ✭✭✭zoro


    int w=6,x=7,y=8,z=9, result;
    result=x*((y==8)?100:999);
    int w = ...... <-- declaration of variables
    how? ::
    eg: result = x*(y==8)?100:99;
    -->
    if(y == 8)
    result = x*100;
    else
    result = x*99;
    <--

    result=x*((y==8)?100:999);
    IF y == 8, THEN result = x* 100, ELSE result = x * 999

    result=(--x*w++)/z++ - ++y;
    x = x - 1;
    result = x * w;
    w = w + 1;
    result = result / z;
    z = z + 1;
    y = y + 1;
    result = result - y;
    Ok, for the next one, if the operator is before the variable (--y) you calculate it straight away, if it is after the variable (x++) you ignore it (it does matter in loops, but not in these examples)
    If you come across --y, you calculate it before moving on. If you come across y++, you calculate it immediately after using the variable y as it is at that moment.
    eg:
    x = 1;
    y = 3;

    ++x + --y + --x + y++ = ??
    2 + 2 + 1 + 2 = 7
    after the calculation:
    x = 2;
    y = 3;

    Is that any clearer now?

    *edit*
    galwaydude18: The only reason that you're receiving this level of help is that you're obviously stressed out over your upcoming exam. As a rule, programmers generally don't give out real code when someone asks for help - the fact that you're having difficulty grasping these basic elements of Java, shows that you probably lack a deeper understanding of the language in general ... and that's something that we can't help you with.

    Remeber that we won't be at your exam with you, and also that at one time, all of us knew absolutely NOTHING about Java. It takes time to learn and master all of these small things - but when you do you'll find that you'll look back on this thread and thing "Damn ... how did I not know that?!"

    Daniel


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    you could write a small java program and then run each step to see what the output is. Might be easier for you to understand.


  • Closed Accounts Posts: 537 ✭✭✭JohnnyBravo


    Whereas I was leaving it open for him to find the answer himself... Like a good programmer should learn to do, rather than have the solution handed on a silver platter.


    Dont over estimate the silver platter way
    Best way to learn is have a working example


  • Registered Users Posts: 834 ✭✭✭fragile


    DRJava is a very useful tool for anybody trying to get to grips with the Java language.
    One of the key distinguishing features of DrJava is its Interactions Pane, which allows you to enter and evaluate Java statements and expressions on the fly. This is remarkably useful for beginning students, who no longer have to learn to write main methods, recompile, and run programs from a command line simply to test how a new class or method behaves. From a teaching standpoint, the Interactions Pane is a very easy way to help students learn to write Java without having to explain the full meaning of syntax like "public static void main", and it also provides an ideal way to perform demonstrations in class. The Interactions Pane can also be used to experiment with your own programs or new libraries, or even to create graphical user interfaces interactively

    It can be downloaded here


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Dont over estimate the silver platter way
    Best way to learn is have a working example

    It is in the short term, but if the person can't explain what something is doing all a working example is going to provide is a cut + paste. This is counter productive for learning.

    It is quite clear from what he has posted so far that working examples will mean nothing to him.


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    Hobbes wrote:
    It is in the short term, but if the person can't explain what something is doing all a working example is going to provide is a cut + paste. This is counter productive for learning.

    It is quite clear from what he has posted so far that working examples will mean nothing to him.

    Thanks to help of everyone eles i now do understand it!!! i went through other past papers this morning and did them all without any problems!!!! :D


  • Registered Users Posts: 2,243 ✭✭✭zoro


    Well done galwaydude18 - best of luck in your exams!


  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    how do you do this? i can not figure it out to save my life! even using my notes is no help to me!!!

    Rewrite the following program sgement using a for loop

    int x=11, y=14;
    while (x<=27)
    {
    System.out.println ("The value of y-x is:" +y-x);
    x+=2;
    }

    Guys your help would be appreciated on this!!!!


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Honestly, read the loop structure carefully, disect what each line does and re-work it into the format of a for loop instead, its really a very simple example.


  • Advertisement
  • Registered Users Posts: 3,695 ✭✭✭galwaydude18


    Dude its simple when you know what your talking about and what it means but I honestly do not know what I do to transform it in to a for loop!!! can you please help me!!! PLEASE???????!!!!


Advertisement