Add two number in java

Java add two numbers example explains you that how you can add two integers

Add two number in java

Java add two numbers example explains you that how you can add two integers

Add two number in java

Add two number in java

In this section you will learn about how to add two number in java. In java adding two number,  first taking the input provided by the user through Scanner class and the input which is in String can't be added, So two add,  convert these String into numeric type. Integer.parseInt() method help you to convert String type to integer type. Now you can add these value into z variable and print the z variable to the console by println() method. Now here is the code for addition of two number in java.

import java.util.Scanner;
public class Add {
	public static void main(String args[])
	{
		System.out.println("");
		System.out.println("Addition of two number");
		System.out.println("Please Enter two number to add :");
		Scanner sin=new Scanner(System.in);
		int x= sin.nextInt();
		int y=sin.nextInt();
		int z=x+y;
		System.out.println("After addition of two number = " +z);
	}
}

Output  of the program

Download  SourceCode