Question

In: Computer Science

Show step-by-step how Java will evaluate the following expression: 8 % 3 + 3 % 2...

Show step-by-step how Java will evaluate the following expression:

    8 % 3 + 3 % 2 – 9 % 2.0 * 5

      15/15 % 7 *2   – 11. /4 * 5

      Solutions

      Expert Solution

      Solution:

      ===============

      a) Here we have % , + , - , * operator

      as per Precedence rule %, * will be evaluated first and then + ,- will be evaluated.

      also these expression will be evaluated form left to right.

      Hence first of all 8%3 will be evaluated which return 2

      then 3 % 2 will be evaluated which return 1

      then 9 % 2.0 will be evaluated which return 1.0

      then 1.0*5 will be evaluated which return 5.0

      finally +,- operation will be performed on these result

      2 + 1 - 5.0 here first 2+1 will be performed then 3-5.0 will performed hence result is -2.0

      b) Here we have /,% , - , * operator

      as per Precedence rule %, * , / will be evaluated first and then - will be evaluated.

      also these expression will be evaluated form left to right.

      Hence first of all 15/15 will be evaluated which return 1

      then 1%7 return 1

      then 1*2 return 2

      then 11./4 return 2.75

      then 2.75*5 will return 13.75

      finally 2 - 13.75 will be evaluated which return -11.75 as result


      Related Solutions

      Show, step by step, how the stack-based algorithm will transform the expression (1 + 2) *...
      Show, step by step, how the stack-based algorithm will transform the expression (1 + 2) * (7 − 2) into a postfix expression, and then how a second stack-based algorithm will compute the value of this postfix expression.
      Show the step by step multiplication using Booth’s Algorithm 1. -8 * 2
      Show the step by step multiplication using Booth’s Algorithm 1. -8 * 2
      I need to show how to calculate step by step! Sephora wants to evaluate the effect...
      I need to show how to calculate step by step! Sephora wants to evaluate the effect of its loyalty program with customer lifetime value (CLV). The expected profits per customer is assumed to be $300 over the next five years, the chur rate is 15% before the program and 10% after Sephora launched the program. The development cost of the program is $200,000,000. Fill in the CLV table below. Calculate the ROI of the loyalty program. With the program Year...
      java Convert the following Infix expression to a Postfix expression. Show all work                            Infix Expres
      java Convert the following Infix expression to a Postfix expression. Show all work                            Infix Expression                                                 Stack                             Postfix Expression ---------------------------------------------------------------------------------------------------------------------------- 8 - 9*(2 + 1/4) + 3*7                                                     (empty)                            (blank) Evaluate the following Postfix expression. Once again, show all work.            Postfix                                               Stack                     Result           ---------------------------------------    --------------------    --------------            2 7 + 12 4 / * 8 5 + -
      GIVEN THE FOLLOWING PSOSTFIX EXPRESSION, SHOW TO USE A STACK TO EVALUATE ITS FINAL VALUE. SHOW...
      GIVEN THE FOLLOWING PSOSTFIX EXPRESSION, SHOW TO USE A STACK TO EVALUATE ITS FINAL VALUE. SHOW STACK CONFIGURATION DETAILS 20 3 18 8 - * 10 + +10 12 - /
      The Following Java expression: S/10 * 10 + 10 – S = C Show that this...
      The Following Java expression: S/10 * 10 + 10 – S = C Show that this expression gives a value of 2 when S contains the int value 78. You must show every step in your working, performing exactly one operation on each line. I have tried to no end to make sense of this and I know there is an order of precedence in the operators but I can't make any sense of it. Could someone please explain this...
      Use the algorithm below to evaluate the following infix expression: a) a + 3 * 4...
      Use the algorithm below to evaluate the following infix expression: a) a + 3 * 4 – 9 b) ( 2 + 6 ) / ( 3 – 5 ) . Algorithm WRITE STEP BY STEP Scan the characters in the infix expression. While there are characters left in the infix expression: Check the next character in the expression. 1. If the next character is operand, remove it from the expression and push it onto the operand stack. 2. If...
      Using Java 8. Write a program that reads an expression in postfix notation, builds the expression...
      Using Java 8. Write a program that reads an expression in postfix notation, builds the expression tree and prints the expression in prefix and infix notation and evaluates the expression. (Hint use a stack)
      create a program in java that will evaluate a logical expression (compound proposition) based on the...
      create a program in java that will evaluate a logical expression (compound proposition) based on the given truth values of individual propositional variables. The logical expression may include the logical AND or the logical OR operators. The NOT operator will be included in the variable names itself. So, a proposition such as ¬a would appear as na in the logical expression. Here is an example of a logical expression using proper notation: a ∧ b ∨ ¬c ∨ d This...
      1. a. Evaluate the following limit: lim ?→4 ( 2? 3−128 √?−2 ) (8 marks) b....
      1. a. Evaluate the following limit: lim ?→4 ( 2? 3−128 √?−2 ) b. Find the number ? ???ℎ ?ℎ?? lim ?→−2 ( 3? 2+??+?+3 ? 2+?−2 ) exists, then find the limit
      ADVERTISEMENT
      ADVERTISEMENT
      ADVERTISEMENT