Java Examples

100+ tutorials, source code, and examples to help you develop creative and technical skills.

Java Program to add two numbers from user Input

Addition.java

/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset App from PlayStore to learn coding*/

/*Java Program to add two numbers from user Input*/
import java.util.Scanner;

class Addition {
    public static void main(String[] args) {

        /* Declare 3 int type variables a,b and c. a and b will hold 2 numbers on which we will perform addition & c will hold the result*/
        int a, b, c;

        Scanner scanner = new Scanner(System.in); // Create an object of scanner class to get input from user.

        System.out.println("Enter First Number");
        a = scanner.nextInt(); // Initialize 'a' variable with first number entered by user;

        System.out.println("Enter Second Number");
        b = scanner.nextInt(); // Initialize b variable with second number entered by user;

        // Perform addition and save the result into c variable.
        c = a + b;

        // Now finally prints the result
        System.out.println("Addition of " + a + " and " + b + " is = " + c);

    }
}

/*----------OUTPUT----------
Enter First Number
5
Enter Second Number
6
Addition of 5 and 6 is = 11
*/

Projects with Source Code + Video Tutorials

You can download our Java and Android Studio Projects with Source Code and Video Tutorials.

Bottom-Navigation-Bar-with-Fragments-+-Animation
Bottom Navigation Bar with Fragments + Animation
Login-and-Register-Activity-Material-UI-design-in-Android-Studio
Login and Register Activity Material UI design in Android Studio
Settings-and-Profile-page-UI-design-in-Android-Studio-with-Example-and-Source-Code
Settings and Profile page UI design in Android Studio with Example and Source Code

If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com

Follow us to learn Coding and get in touch with new Technologies.