Computer Applications
Write the value of n and m after execution of the following code.
int m;
int n;
m = 5;
n = (5 * ++m) % 3;
System.out.println("n = " + n + "m =" + m);
Java Operators
8 Likes
Answer
Output
n = 0m = 6
Explanation
The statement n = (5 * ++m) % 3; is evaluated as follows:
n = (5 * ++m) % 3; [m = 5]
⇒ n = (5 * 6) % 3; [Prefix operator first increments the value and then uses it. So, m = 5 + 1 = 6 and then it is used in the expression]
⇒ n = 30 % 3;
⇒ n = 0;
So, final value of m is 6 and n is 0.
Answered By
5 Likes
Related Questions
Find the output of the following code.
String str = "I Love My Family"; System.out.println(Integer.toString(str.length())); System.out.println(str.substring(12));Write a Java statement for the following mathematical expression :
V = πr2h
Predict the output
(a) Math.pow(3.4, 2) + 2 * Math.sqrt(64)
(b) Math.ceil(3.4) + 2 * Math.floor(3.4) + 2
If a = 24, b = 15, find the value of:
a += b++ * 5 / a++ + b