Addition of Two Number in Java – A Beginner’s Guide
Java is a popular programming language used for building everything from mobile apps to enterprise software. One of the first programs most beginners write is the addition of two number in Java. It’s a simple task, but it helps in understanding how variables, input/output, and operators work.
Let’s look at how to perform this basic operation.
Java Program for Addition of Two Number
Output:
Explanation:
-
int a = 10;andint b = 20;– We declared two integer variables and assigned values. -
int result = a + b;– We used the+operator to add the numbers. -
System.out.println(...)– This line displays the output on the console.
Try It With User Input
To make it more dynamic, here’s how you can take user input:
Conclusion
The addition of two number in Java is a fundamental concept that helps you understand how Java handles variables, input, and output. It’s a great starting point for beginners who are just stepping into programming with Java.
Keep practicing and try extending the program with subtraction, multiplication, or even GUI-based input. Happy coding!
Comments
Post a Comment