Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 :

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote