Menu
Topics Index
...
`

Creating Variables and Arithmetic Operators


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Variables and Arithmetic Operators
What will be the values of var_a, var_b, var_c? After execution of the program.
public class ValuesAre {
    public static void main(String args[]) {
        int var_a = 20, var_b = 20, var_c = 20;
        var_c += var_a++;
        var_c -= --var_b;
        System.out.print("var_a=");
        System.out.println(+var_a);
        System.out.print("var_b=");
        System.out.println(+var_b);
        System.out.print("var_c=");
        System.out.println(+var_c);
    }
}

A. 21, 19, 21
B. 21, 19, 22
C. var_a=21
var_b=19
var_c=21
D. var_a=21
var_b=19
var_c=22
E. Some other values
F. Compilation Error or Runtime Error
Topic: Arithmetic Compound Assignment Operators In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

c

Posted by Sreenath Vallapaneni    2013-09-04 04:14:16


c..bcoz..a is post in first 20 is added to c and den a is incrmntd to 21:a-21;after it for b pre inc so b gets 19 and 19 is subtracted from 40;hence b-19;c-21

Posted by Bhavya Rishitha    2013-09-04 04:16:33


c=20+20=41  but a=21 and c=40-19=21   so a=21 b=19 c=21

Posted by Sreenath Vallapaneni    2013-09-04 04:22:09


Congratulations Bhavya Rishitha. You are this dose winner. Please send us your mobile details in a private message and we will process the recharge asap.

Posted by Merit Campus    2013-09-05 03:54:43


© meritcampus 2019

All Rights Reserved.

Open In App