Sum of Two Integer Number in Java Program

We will learn how to add two integer number in Java Program.

class SumOfTwoNumber
{
  public static void main(String ar[])
  {
    Scanner sc = new Scanner(System.in);
    int num1, num2, sum;
    System.out.print("Enter First Number: ");
    num1=sc.nextInt();
    System.out.print("Enter Second Number: ");
    num2=sc.nextInt();
    sum = num1 + num2;
    System.out.println("Sum of Two Number is: "+ sum);
  }
}

Enter First Number: 10
Enter Second Number: 20
Sum of Two Number is: 30
  1. We create three variable num1, num2, sum.
  2. num1 variable store first number and num2 variable store second number.
  3. sum variable store adding of two number like num1 + num2.
  4. and then print sum variable that store sum of two numbers.

Be the first to comment

Leave a Reply

Your email address will not be published.


*