Sum of Two Numbers

Write a Program in Java to display sum to integers by taking input from the user .

import java.util.Scanner;

public class AddTwoNumbers2 {

    public static void main(String[] args) {

         int num1, num2, sum;

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter First Number: ");

        num1 = sc.nextInt();

                System.out.println("Enter Second Number: ");

        num2 = sc.nextInt();

         sc.close();

        sum = num1 + num2;

        System.out.println("Sum of these numbers: "+sum);

    }

}

Output

Leave Comment

Important Topics

Title
Run and Compile
Hello World Program
User Input
Add Numbers
Sum of Two Numbers
Even Numbers
Odd numbers from 1 to n or 1 to 100
Even or Odd number
Average of 3 numbers
Fibonacci Series using loops
Generate random number
Largest of three Numbers
Decimal to octal conversion
Quotient and Remainder
Simple Interest
Compound Interest