a. Evaluate the expression, 4 + 6 * 2
Operator Precedence:
An expression is a statement, which will hold a value when it is evaluated. A mathematical expression will hold multiple operators and grouping symbols; an expression will be evaluated based on the precedence of the operator. The rules of the operator precedence are given below.
- Unary negation (-) and brackets () will have the highest priority.
- Multiplication (*), division (/) and modulus (%) will have the next highest priority.
- Addition (+), subtraction (-) will have the lowest priority.
b. Evaluate the expression, 10 / 5 + 8
Explanation of Solution
In the above expression, the division “/” operation will be evaluated first and next “+” addition operation will be executed as shown below:
St...
c. Evaluate the expression, 12 / 4 + 16 / 2
Explanation of Solution
In the above expression, the division “/” operation will be evaluated first and next “+” addition operation will be executed as shown below:
Step 1:
�...
d. Evaluate the expression, 17 / 2
Explanation of Solution
In the above expression, the division “/” operation will be evaluated first and the quotient is returned as the result as shown b...
e. Evaluate the expression, 22 / 5
Explanation of Solution
In the above expression, the division “/” operation will be evaluated first and the quotient is returned as the result as shown b...
f. Evaluate the expression, 39 / 10
Explanation of Solution
In the above expression, the division “/” operation will be evaluated first and the quotient is returned as the result as shown be...
g. Evaluate the expression, 19 % (2 + 3)
Explanation of Solution
In the above expression, the values inside the brackets are evaluated first and then modulus (%) operator is evaluated and the remainder is returned as a result as shown below:
...h. Evaluate the expression, 3 + 4 * 20 / 3
Explanation of Solution
In the above expression, the multiplication “*” operation will be evaluated first, next division “/” operation is evaluated and at last, addition “+”operation will be evaluated as shown below:
...i. Evaluate the expression, 36 % (6 + 2)
Explanation of Solution
In the above expression, the values inside the brackets are evaluated first and then modulus (%) operator is evaluated and the remainder is returned as a result as shown below:
...j. Evaluate the expression, 8 % 2 * 0
Explanation of Solution
In the above expression, the values inside the brackets are evaluated first and then modulus (%) operator is evaluated and the remainder is returned as a result as shown below:
...
Trending nowThis is a popular solution!
Chapter 2 Solutions
EBK JAVA PROGRAMMING
- Write a Java regular expression for each of the following: a. Phone numbers, such as (609) 555-1234 b. Social Security numbers, such as 123-45-6789 c. Dates, such as December 31, 1999arrow_forward• FormulaEvaluator.java Requirements: Evaluate the following expression for any value of the variable x, and save the result in a variable of the type double. You must use the abs(), pow(), and sqrt() methods of the Math class to perform the calculation. You may use a single assignment statement with a somewhat large expression, or you may break the expression into multiple assignment statements. The latter may be easier to debug if you are not getting the correct result. 5x +3} ( √8x* — 6x²³ + 4x² + |20x+1) (9x³+7x² +5x+3) Next, determine the number of digits to the left and to the right of the decimal point in the result. [Hint: You can convert the double variable into a String variable using the static method Double.toString(result). Then, on this String variable use the indexOf() method from the String class to find the position of the decimal point (".") and use the length() method to find the length. Knowing the location of the decimal point and the length of the String, you…arrow_forwardJAVA Programming Language: According to the American Heart Association, as you exercise you should periodically check your heart rate to ensure you are in your target zone. Your target zone is a range that is 50% to 85% of your maximum heart rate. The formula for calculating a persons maximum heart rate is 220 minus your age in years. Write a program that reads the users current heart rate, birthday, and the current day (each consisting of month, day, and year). The program should calculate the persons age (in years), the person's maximum heart rate, and the person's target heart rate zone range. Output the users age, current heart rate, target zone range. If their heart rate is in the target zone congratulate them, if it is out of their target zone warn them. Required Methods (Write these first and use them in your algorithm): (your code, particularly for computeAge, must be 100% clear and documented - it's the core of this assignment!) int computeAge(int birthMonth, int birthDay,…arrow_forward
- 5. You are playing a game that has two dice - one die has 6 sides numbered 1 through 6 and the second die has 8 sides numbered 1 through 8. A turn involves rolling both die together. Write Java code to play 1,000 turns and keep track of the sum of the two dice in each roll I.e, (2 through 14). When all 1,000 turns have been completed, print a formatted table showing the value of the sum of the two dice (2 through 14) and the number of times that value occurred.arrow_forwardAfter calculating the ranking score according to the ALES (Academic Postgraduate Exam) score, foreign language score and graduation grade point average of the candidate applying for graduate education, write the program in JAVa, which will be able to enter the ranking on the screen. (All points are given over a hundred.)arrow_forwardPlease help with the following: in JAVAarrow_forward
- Please answer this question in Java language with a screenshot of the output and .java filearrow_forward(PLEASE USE BASIC JAVA NOT COMPLEX I AM A BEGINNER THANKS) Canadian phone number has the following format: +1 (604) 295- 8959 Area Code= Three digits starting with 2-9Prefix= Three digits starting with 2-9Subscriber= Any four digits 0-9Write a java program, using loops, that asks the user to enter a phone number then if correct print theArea Code, Prefix, and Subscriber numbers. If not correct, print what is wrong. Sample run:Enter a number or -99 to quit: +1 (604) 277-9999The number is correct with area code: 604, prefix 277, and subscriber 9999Enter a number or -99 to quit: 1 (104) 277-0123Country code doesn’t start with + and area code doesn’t start with a 2-9 number.arrow_forwardThis needs to be done in Java! (Calculating Sales) An online retailer sells five products whose retail prices are as follows: Product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49 and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows: product number quantity sold Your program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT