Using Variables in Java
Write a program that declares and initializes two integer variables a
and b
with the values 10 and 20 respectively. Then, declare a third integer variable sum
and assign it the sum of a
and b
.
Instructor solution
Think you've got it?
How do you use variables in an arithmetic operation in Java?
- A.
By using the variable names in the arithmetic expression.
- B.
By using the variable names enclosed in quotes in the arithmetic expression.
- C.
By using the data types of the variables in the arithmetic expression.
- D.
By using the values of the variables in the arithmetic expression.
You may exit out of this review and return later without penalty.