In Java, an assignment statement itself has a value. It\'s the value of the RHS
ID: 3675755 • Letter: I
Question
In Java, an assignment statement itself has a value. It's the value of the RHS of the assignment statement. Thus in this statement: int x = y = 1; x gets the value of the assignment statement y = 1, which is the value of the assignment statement's RHS, which is 1. Any variable used in the RHS must exist already. A slightly clearer way to right it would be: int x = (y = 1); What is the final value of the variable n in this example? boolean b = true, c = false; int n = 3, m = 4; c = n == m--; if(b = c) n *=m;
Explanation / Answer
MyFirstJavaProgram.java
public class MyFirstJavaProgram {
public static void main(String []args)
{
boolean b = true, c = false;
int n = 3, m = 4;
c = n == m--;
if(b = c)
n *=m;
System.out.println("n = " + n);
}
}
Output :
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.