Computer Applications
Evaluate the expression:
3 * 6 % 5 * 4 / 2 * 7 % 5
Java Operators
1 Like
Answer
Step 1: Multiplication and Modulus have same precedence, so we evaluate left to right.
- 3 * 6 = 18
- 18 % 5 = 3 (because 18 ÷ 5 leaves remainder 3)
Expression now: 3 * 4 / 2 * 7 % 5
Step 2: Continue left to right (multiplication, division, modulus have same precedence):
- 3 * 4 = 12
- 12 / 2 = 6
- 6 * 7 = 42
- 42 % 5 = 2 (since 42 ÷ 5 leaves remainder 2)
Final result: 2
Answered By
2 Likes
Related Questions
Consider the following program segment and answer the questions given:
for(int k=1;k<=5;k++) System.out.println(k); System.out.println(k);(a) Will the program segment get executed successfully?
(b) If not, state the type of error?
(c) How do you correct the program if it has any error?Consider the array:
int a[]={12, 35, 40, 22, 56, 9, 70};(a) In the above given array, using linear search, how many iterations are required to check for the existence of the value 56?
(b) If the array is arranged in descending order, how many iterations are required to check for the existence of 56 using linear search?
Consider the following program which calculates the Norm of a matrix. Norm is square root of sum of squares of all elements.
Fill in the blanks (a) and (b) with appropriate java statements:
double norm() { int x[][]={{1,5,6},{4,2,9},{6,1,3}}; int r, c, sum=0; for(r=0;r<3;r++) { for(c=0;c<3;c++) sum=sum+_____(a)_____; } ____(b)________; }Give the output of the following program segment:
for(r=1;r<=3;r++) { for(c=1;c<r;c++) { System.out.println(r); } }