This discussion is archived
11 Replies Latest reply: Dec 6, 2012 2:58 PM by EJP RSS

Simple Questions.

apollon27 Newbie
Currently Being Moderated
Hello I am new to Java Programming,
By the way I am a Forms Developer, but I thing it's good to know Java, so I am reading a book that has some exercises,
and I want to make sure if I have answered them correct.

Question 1
State whether each of the following is true or false. If false, explain why.

a) Java operators are evaluated from left to right.
b) The following are all valid variable names: underbar_, m928134, t5, j7, her_sales$,
his_$account_total, a, b$, c, z and z2.
c) A valid Java arithmetic expression with no parentheses is evaluated from left to right.
d) The following are all invalid variable names: 3g, 87, 67h2, h22 and 2h.

I answer

a) False b) True c) True d) False because h22 is valid.

Am I right?

----------------

Question 2

Which of the following Java statements contain variables whose values are modified?
a) p= i+j+ k+7;
b) System.out.println( "variables whose values are modified");
c) System.out.println( "a=5" );
d) value = input.nextInt();

I think a)


-----------------
Question 3

Given that y=ax^3^+ 7, which of the following are correct Java statements for this equation?
a) y= a*x* x*x+7; --> correct
b) y= a*x* x*(x +7 );
c) y= (a*x )*x* (x+7 );
d) y= (a*x )*x* x+7; ---> correct
e) y= a*(x xx )+7; ---> correct
f) y= a*x* (x*x +7 );








Thank you.
  • 1. Re: Simple Questions.
    EJP Guru
    Currently Being Moderated
    I answer

    a) False b) True c) True d) False because h22 is valid.

    Am I right?
    Nearly. (C) is false. Consider a+b*c.
    Question 2

    I think a)
    Also (d). 'value' is modified.
    Question 3

    Given that y=ax^3^+ 7
    Given what? This formula must contain a typo. Question 3 is therefore unanswerable.
  • 2. Re: Simple Questions.
    rp0428 Guru
    Currently Being Moderated
    >
    I am reading a book that has some exercises,
    and I want to make sure if I have answered them correct.
    >
    What book? Provide a reference. If the answers are not in the book you should use a different book.

    The best way to accomplish your goal is to use a book that provides the answers and explains them.
  • 3. Re: Simple Questions.
    apollon27 Newbie
    Currently Being Moderated
    Hello the book I read is
    "Java- How to program 9ed" Paul Deitel, Harvey Deitel

    After each chapter, it has some exercises with solutions and exercises without solutions.
    Chapter 2 that I am reading has 6 exercises with answers, and 27 exercises without answers!

    Only Instructors have access to the solutions!!!!

    Do you recommend a better book. I am new to Java, but not to programming, I have professional experience with PL/SQL, Oracle Forms/Reports

    It says :

    Instructor Supplements
    The following supplements are available to qualified instructors only through Pearson Education’s Instructor Resource Center (www.pearsonhighered.com/irc):
    • PowerPoint slides containing all the code and figures in the text, plus bulleted items that summarize key points.
    • Test Item File of multiple-choice questions (approximately two per book section).
    • Solutions Manual with solutions to the vast majority of the end-of-chapter exercises.

    Please do not write to us requesting access to the Pearson Instructor’s Resource Center which contains the book’s instructor supplements, including the exercise solutions. Access is limited strictly to college instructors teaching from the book. Instructors may obtain access only through their Pearson representatives.
  • 4. Re: Simple Questions.
    972409 Newbie
    Currently Being Moderated
    EJP wrote:
    Question 3

    Given that y=ax^3^+ 7
    Given what? This formula must contain a typo. Question 3 is therefore unanswerable.
    I guess it's mathematical expression. So I am guessing there is no type.

    Edited by: 969406 on Nov 4, 2012 1:32 PM
  • 5. Re: Simple Questions.
    EJP Guru
    Currently Being Moderated
    It isn't a mathematical expression: it must contain a typo. The second '^' is in error. The rest of it looks like a mathematical function using ^ for exponentiation. Please clarify.

    NB the questions about left to right may concern a common misconception. They may even be the common misconception. The operands of an expression are evaluated left to right. The expression itself is evaluated according to the rules of precedence. So for example in a+b*c, a, b, and c are evaluated in that order, but b*c is evaluated before applying the +.
  • 6. Re: Simple Questions.
    rp0428 Guru
    Currently Being Moderated
    >
    I guess it's mathematical expression. So I am guessing there is no type.
    >
    He said 'typo' not 'type'. This 'y=ax^3^+ 7' should probably be this 'y=ax^3+ 7'. So the question is probably
    >
    Given that y=ax^3+ 7, which of the following are correct Java statements for this equation?
    a) y= a*x* x*x+7; --> correct
    b) y= a*x* x*(x +7 );
    c) y= (a*x )*x* (x+7 );
    d) y= (a*x )*x* x+7; ---> correct
    e) y= a*(x xx )+7; ---> correct
    f) y= a*x* (x*x +7 );
    >
    So in ax^3+7 the exponentiation operator ('^') binds the x and the 3. So x^3 can be written as x*x*x so the expression is now
    >
    a*x*x*x+7 - so answer 'a' is correct.
    >
    If you add parenthesis around the 'x's you get
    >
    a*(x*x*x)+7 - so answer 'e' is correct
    >
    And since the multiplication operator ('*') is associative you can do any of the series of multiplication operations first so
    >
    (a*x)*x*x+7 - so answer 'd' is correct
    >
    The other three answers are wrong because they perform addition before the multiplication; multiplication has a higher precedence than addition.
  • 7. Re: Simple Questions.
    apollon27 Newbie
    Currently Being Moderated
    Thank you very much for the answers:

    x^3^ 3 is superscript. means x*x*x but how can I write it?
  • 8. Re: Simple Questions.
    EJP Guru
    Currently Being Moderated
    x*x*x is x ^3^. You need a space before the first ^.
  • 9. Re: Simple Questions.
    972748 Newbie
    Currently Being Moderated
    i just checked the book.. the expression is as you thought.. 'y=ax^3+ 7'.
  • 10. Re: Simple Questions.
    978238 Newbie
    Currently Being Moderated
    Question 1
    State whether each of the following is true or false. If false, explain why.

    1.a) Java operators are evaluated from left to right

    true... example ----- a+b*(2+2)

    Here we are do operation from left to right...here we start operation from (2+2)



    b) The following are all valid variable names: underbar_, m928134, t5, j7, her_sales$,
    his_$account_total, a, b$, c, z and z2.

    In java we can use underscore( _ ) at the time of variable declaration...
    here we can use numeric value but we can use aftr character value oly...

    C.)A valid Java arithmetic expression with no parentheses is evaluated from left to right.

    i dunno exact answer..
    D.) The following are all invalid variable names: 3g, 87, 67h2, h22 and 2h.

    False because h22 is valid variable...
    2.

    Which of the following Java statements contain variables whose values are modified?

    a) p= i+j+ k+7;
    b) System.out.println( "variables whose values are modified");
    c) System.out.println( "a=5" );
    d) value = input.nextInt();

    A is the answer... because there we modify the values for j and k... bt is not possible in other options..
  • 11. Re: Simple Questions.
    EJP Guru
    Currently Being Moderated
    Here we are do operation from left to right...here we start operation from (2+2)
    Which is not on the left. It's on the right. Your answer is therefore not only wrong but self-contradictory. Which is all the more strange, as the correct answer was given a month ago above, with example.
    C.)A valid Java arithmetic expression with no parentheses is evaluated from left to right.

    i dunno exact answer..
    Also strange, as it's been given above. It's been sitting there for a month. Did you read the thread before you pointlessly revived it?
    A is the answer... because there we modify the values for j and k... bt is not possible in other options
    Complete rubbish. You've named two variables that aren't modified, and missed both the ones that are modified. And once again the correct answer appears above.

    You get an F for your answers , a Z for not reading the thread and spotting the correct answers, which are even marked as being correct, and another Z for being a month late to help the original poster. Your guesses aren't even as good as the original poster's answers. If you can't add value please don't bother.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points