Are you Searching Add two numbers in java programing? You are on the right  webstite. we give you a big collection java  Programing We are provide Add two numbers in java programing  and easy to understand . In the first Example  we specify the value of both the numbers in the program itself. The second Example takes both the numbers entered by user and display add of two number.


Example 1 : Add two numbers

public class AddExample1 {

   public static void main(String args[]) {
        
      int x = 20, y = 30, A;
      A = x + y;

      System.out.println("Add two numbers is : "+sum);
   }
}
Java

Output:

Add two numbers is 50




Example 2 : Add two numbers using Scanner

import java.util.Scanner;


class AddExample2{
    public static void main(String args[]) {

        int x, y, A;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter two numbers:");
        x = sc.nextInt();
        y = sc.nextInt();

         A= x + y;

        System.out.println("Add two numbers is:" + A);

    }
}


Java

Output:

Enter two numbers: 20
30
Add two numbers is: 50



Java Program How  to add two numbers