Home / Questions / What will be the output of the following code? int m = 2; int n = 15; for(int i = 1; i < 5; i++) { m += i; // m = m + i n -= i; // n = n - i } System.out.println("m = " + m); // Output for m System.out.println("n = " + n); // Output for n
Explanatory Question

What will be the output of the following code?
 
int m = 2;
int n = 15;

for(int i = 1; i < 5; i++) {
    m += i; // m = m + i
    n -= i; // n = n - i
}
System.out.println("m = " + m); // Output for m
System.out.println("n = " + n); // Output for n

 

👁 62 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

Output:

  • m = 12
  • n = 5