Java Program to Add Two Numbers

In this post, we’ll look at how to create a java programme to add two numbers. Two numbers are assigned to two java integer variables in the Java programme. The sum of the two numbers will be saved in another java integer variable. The total will be displayed in the java program.

package in.yawin;

public class AddTwoNumbers {

	public static void main(String[] args) {
		int a = 5;
		int b = 4;

		System.out.println("a value is " + a);
		System.out.println("b value is " + b);

		int c = a + b;
		System.out.println("c value is " + c);



a value is 5
b value is 4
c value is 9


This Java programwill demonstrate how to add two numbers. A main method is added to the java class AddTwoNumbers. Two java integer variables are created and assigned two integer values in the main method. The integer value 5 is assigned to the variable a. The integer value 4 is assigned to the variable b. Variable c stores the sum of two variables. The formula is (c = a + b). The variable c prints the sum of two variable values.