Sum Two Integers Value using Java

0
57

In my last tutorial entitle “Printing Hello Word in Java”, discuss the structure of Java programs and its parts. This tutorial will teach you on how you can sum two integers values using Java. Integer is one of the examples of Data type in Java.

Remember that there are many Data type that handles Number values and Integer can only handle whole numbers.

Sum Two Integer Value in Java steps

1.Create a new project in Netbeans and name the project on what you want to name it.

2.Insert a main method inside your Class.

  1. public static void main(String args[]){
  2.  
  3. }

3.Declare three integer variables and initialized it inside your new created main method.

  1. int num1=2;
  2. int num2=2;
  3. int total=0;

3.Insert the code below to calculate and display the result.

  1. total = num1 + num2;
  2. System.out.println("The sum is :" + total);

4. Run your program and the result should look like the image below.

5. Complete source code

  1. public class SumTwoIntegers {
  2. public static void main(String args[]){
  3. int num1=2;
  4. int num2=2;
  5. int total=0;
  6. total = num1 + num2;
  7. System.out.println("The sum is :" + total);
  8. }
  9. }

 

If you have any comments or suggestion about on Sum Two Integers Value using Java, Please feel free to leave your comment below, use the contact page of this website or use my contact information.

Email: info@kmjtech.net  |  Cell. No.: 09468362375

 

Readers might check this:

How to Create Basic Calculator using Java

How to Check the Highest Number Value using Java

Facebook Comments
(Visited 56 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here