sum of two numbers in java

In this article, we are going to write program in java to perform sum of two numbers.


If n1=5, n2=5, then the output will be 10.


  • Take input for first number.
  • Take input for second number.
  • print first number + second number.

Java code to perform sum of two numbers.

package gangforcode;
import java.util.*;
public class SumOfTwoNumbers {

	public static void main(String[] args) {
		Scanner sc= new Scanner(;
		System.out.println("Enter first number");
		int n1=sc.nextInt();
		System.out.println("Enter second number ");
		int n2=sc.nextInt();
		int sum=0;
		System.out.println("sum of two numbers is "+sum);



sum of two numbers.

Leave a Comment