Task: Write and Execute Java Addition Program. This Java Programming Tutorial will provide and explain the source code of a basic addition program in Java. The program will input two numbers from the user at run time. The Java program will calculate the sum of these two numbbers and will display the answer of addition.
Note: You must know How to get input from user in a Java Console Application
You may also like to read How to Write and Execute First Java Program in NetBeans
The Complete Procedure to Write, Compile and Execute Java Addition Program
Start NetBeans IDE.
Click on File menu and select New project. A new dialog box will open.
Select ‘java’ and click on Java Application. Click on next button.
Type the name of your Java project in the Project name text box.
Clcik on Finish button.
You will get a code editor window with a default and basic Java program template. Edit the default template as shown in the image below.
Type the source code to add two numbers in Java.
Click on Run menu and select Run Project to execute your Java Addition project. The program will be compiled first. The Java compiler ‘javac’ will convert the Java source code ‘Addition.java’ in to ‘Addition.class’ file. This class file is called the Java Byte Code. This Java byte code is iterpreted by Java Virtual Machine – JVM will interpret and execute this byte code.
The source code of the Basic Add Two Number Program in Java
Enter first number=100
Enter second number=200
Result of Addition=300