
How to add two int numbers in Java Example

Here is a java example that accepts two integer from the user and find their sum.
import java.util.*;
class AddNumbers
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter first number: ");
int num1=input.nextInt();
System.out.print("Enter second number: ");
int num2=input.nextInt();
int sum=num1+num2;
System.out.println("Result is: "+sum);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
