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 );
Solution
The correct answers for the assignment operations are as follows:
-
c = a + b;Here,ais 10 andbis 20. So,cwill be10 + 20which is30. So, the output ofSystem.out.println("c = a + b = " + c );will bec = a + b = 30. -
c += a ;This is equivalent toc = c + a;. Here,cis 30 andais 10. So,cwill be30 + 10which is40. So, the output ofSystem.out.println("c += a = " + c );will bec += a = 40. -
c -= a ;This is equivalent toc = c - a;. Here,cis 40 andais 10. So,cwill be40 - 10which is30. So, the output ofSystem.out.println("c -= a = " + c );will bec -= a = 30. -
c *= a ;This is equivalent toc = c * a;. Here,cis 30 andais 10. So,cwill be30 * 10which is300. So, the output ofSystem.out.println("c *= a = " + c );will bec *= a = 300.
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
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.