Following are the java code to add sum to number:
public class Main//defining a class Main
{
public static void main(String[] axb)//defining main method
{
int sum = 1;//defining integer variable
int number = 2; //defining integer variable
sum += number;//using sum variable that add sum to number
System.out.println(sum);//print value
}
}
Output:
3
Code Explanation:
- Defining a class Main.
- Inside the class defining the main method.
- In the main method two integer variable "sum and number" is declared that holds "1, 2" value respectively.
- Inside this code, a sum variable is declared that adds sum to the number and store its value into the "sum" variable, and use the print method to print its value.
Defining the wrong choices:
- In option A, it is wrong because the number variable is used to store the sum variable value.
- In option B, it is wrong because the number variable is used to add the number and sum variable value.
Therefore, "Option C" is correct.
Learn more:
brainly.com/question/19959452