Home Java Learn-java-in-a-day Add two number in java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Add two number in java

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

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

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 10, 2013

Ask Questions?    Discuss: Add two number in java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com