Getting Started with Addition of Two Number in Java

 If you're learning Java programming, one of the simplest and most important tasks to understand is the addition of two number in Java. This basic operation teaches you how variables, data types, and operators work together in Java.

Example: Addition Using Variables

Here is a very simple example where two numbers are added using variables:


public class AddTwoNumbers { public static void main(String[] args) { int number1 = 5; int number2 = 15; int sum = number1 + number2; System.out.println("Addition of two number in Java: " + sum); } }

Output:


Addition of two number in Java: 20

What This Program Does

  • It creates two integer variables: number1 and number2.

  • It adds them using the + operator.

  • The result is stored in the variable sum.

  • The program prints the result on the screen.

Why Learn This?

Understanding the addition of two number in Java is essential because:

  • It helps you learn how to declare and use variables.

  • You understand how to use operators.

  • It’s the foundation for more complex logic like functions, loops, and conditionals.

Final Thoughts

While this might look like a very basic program, it’s the perfect starting point for anyone new to Java. Once you're confident with this, try accepting user input, using functions, or performing operations with different data types.

Comments

Popular posts from this blog

Python features

How to Find GCD of Two Numbers in Java

Master AWS with the Best Training in Pune – Join Technogeeks Today!