Java Program To Add Two Numbers

Write Java program to add two numbers

// WAP to add two integer numbers

import java.util.Scanner;
public class Addition 
{
    public static void main(String[] args)
    {
        int n1,n2;
        
        // object 'sc' created to scan data
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter number 1 :--> ");
        n1 = sc.nextInt();

        System.out.println("Enter number 2 :--> ");
        n2 = sc.nextInt();

        int add = n1 + n2;
        System.out.println("Addition of "+ n1 + " + " + n2 + " = " + add);

    }    
}

Output:


<< Previous | Next >>


Leave a Reply

Your email address will not be published.