Write A Program To Add Two Numbers | Java Programs

Output:

*** Add Two Numbers ***

Enter first number: 3
Enter second number: 5
Sum of 3 and 5 is: 8

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class AddTwoNumbersTakingInput {

    public static void main(String[] args) {

        int num1 = 0;
        int num2 = 0;
        int sum = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("*** Add Two Numbers ***" + "\n");
        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 " + num1 + " and " + num2 + " is: " + sum);
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon