Friday 14 March 2014

Java program to add two numbers



 
Java program to add two numbers :- Given below is the code of java program that adds two numbers which are entered by the user.

Java programming source code


import java.util.Scanner;

class AddNumbers {
    public static void main(String args[]) {
        int numOne = 0;
        int numTwo = 0;
        int result = 0;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter first number: ");
        numOne = sc.nextInt();

        System.out.print("Enter second number: ");
        numTwo = sc.nextInt();

        result = numOne + numTwo;
        System.out.println("Sum of entered numbers = " + result);

        sc.close();
    }
}


Output of program: