java

Find the Sum of Two Numbers in Java

In this tutorial, we are going to see how to write a program that calculates the sum of two integers in Java.
 

Example: Find the Sum of Two Numbers in Java
public class Main {

    public static void main(String[] args) {
        
        int n1 = 2;
        int n2 = 4;

        int sum = n1 + n2;

        System.out.println("The sum is : " + sum);
    }
}

 
Output:

The sum is : 6
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *