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.
      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...
      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)
      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
      Write an algorithm to evaluate an infix expression in Java. Calculate its running time
      Write an algorithm to evaluate an infix expression in Java. Calculate its running time
      2. Calculation of the atom economy of the reaction according to the following expression (8): %...
      2. Calculation of the atom economy of the reaction according to the following expression (8): % Atom Economy = (Mol. Wt. of Product / S(Mol. Wt. of Reactants)) x 100 How might the atom economy be improved by changing the structure of one of the starting materials? Can you predict any drawbacks to doing this?
      How do I graph this step function? f(t) = -3(2t-3)H(t-2) + (2t-1)H(t-1) Please show step by...
      How do I graph this step function? f(t) = -3(2t-3)H(t-2) + (2t-1)H(t-1) Please show step by step. How is it the same graph as f(t) = H(t-1)-3H(t-2)+H(t-1)*2(t-1)-H(t-2)*6(t-2)? Please show why as well.
      ADVERTISEMENT
      ADVERTISEMENT
      ADVERTISEMENT