Knowee
Questions
Features
Study Tools

What is the correct answer for following assignment operations?            int a = 10;            int b = 20;             int c = 0;              c = a + b;             System.out.println("c = a + b = " + c );              c += a ;             System.out.println("c += a  = " + c );              c -= a ;             System.out.println("c -= a = " + c );              c *= a ;             System.out.println("c *= a = " + c );

Question

What is the correct answer for following assignment operations?            int a = 10;            int b = 20;             int c = 0;              c = a + b;             System.out.println("c = a + b = " + c );              c += a ;             System.out.println("c += a  = " + c );              c -= a ;             System.out.println("c -= a = " + c );              c *= a ;             System.out.println("c *= a = " + c );

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answers for the assignment operations are as follows:

  1. c = a + b; Here, a is 10 and b is 20. So, c will be 10 + 20 which is 30. So, the output of System.out.println("c = a + b = " + c ); will be c = a + b = 30.

  2. c += a ; This is equivalent to c = c + a;. Here, c is 30 and a is 10. So, c will be 30 + 10 which is 40. So, the output of System.out.println("c += a  = " + c ); will be c += a  = 40.

  3. c -= a ; This is equivalent to c = c - a;. Here, c is 40 and a is 10. So, c will be 40 - 10 which is 30. So, the output of System.out.println("c -= a = " + c ); will be c -= a = 30.

  4. c *= a ; This is equivalent to c = c * a;. Here, c is 30 and a is 10. So, c will be 30 * 10 which is 300. So, the output of System.out.println("c *= a = " + c ); will be c *= a = 300.

This problem has been solved

Similar Questions

How many types of assignment operators in java?Options: Pick one correct answer from below3546

Which of the following are valid assignment statement in Java? You can select more than one answer.Group of answer choicesfloat x = 3.5;int x = 3.5;boolean x = 0;double x = 3.5;int x = (int)3.5;

Q2: Suppose that A is an array of int, and that B is declared to be a pointer of type int *. Which of the following is not a valid assignment statement, assuming that both B and the elements of A have been initialized to suitable values:B = A;B = &A[3];B = *(A + 3);B = (A + 3);B = A + *A;

Which of the following method are accepted for assignment? a) 8=x=y=z b) x=8=y=z c) x=y=z=8 d) None

Question40Max. score: 4.00In C, you are working with assignment operators.You are given two variables a and b. If you are required to perform various operations using these assignment operators, then which of the following statements about these operations are correct:a + = b can also be written as a + 1 = ba - = b can also be written as a = a - ba * = b can also be written as a *1 = ba / = b can also be written as a = a / b

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.