Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Addition of two Number in Class 
 

In this program we will learn how to calculate any two number. Java is a object oriented programming language in which uses of class consists of a collection of type of encapsulation instance variables and type of methods.

 

Addition of two Numbers in Class

                         

In this program we will learn how to calculate the sum of any two number. Java is a object oriented  programming language in which uses of class consists of a collection of type of encapsulation instance variables and type of methods. We are going to use in this program of class method. Class is a cohesive package that consist of a particular values at compile time. The class  is describe the rules by which object are referred to as instance value. 

Description this program

Here in this program  we are going to use addition of  two number. First of all, we have to define class named "SumExample". We are going to define two integer type values in the class method. After that we are going to create buffer reader object for read the text charactor- input stream and buffer is also provide for the efficient read of charactor values. As in this program we are going to insert certain instruction by creating buffer reader class. it is necessary to use 'try' and 'catch'. Now we are going to create parseInt method for read text line. After that we have to create object and return the integer type values. So output will be display by using "sum= sum1.x+sum1.y".

Here is the code of this program

import java.io.*;
public class SumExample{
    public int x;
    public int y;
    public static void main(String args[]){
      try {
    SumExample sum1= new SumExample();
    int sum;
    BufferedReader object= new BufferedReader (new InputStreamReader(System.in));
    System.out.println("Enter number:");
    System.out.print("Enter number x:=""");
    sum1.x=Integer.parseInt(object.readLine());
    System.out.print("Enter number y:=""");
    sum1.y=Integer.parseInt(object.readLine());
    sum= sum1.x+sum1.y;
    System.out.println("Sum is:"+ sum);
      }
    catch(Exception e){}
    }
  }

 

Download this Example

                         

» View all related tutorials
Related Tags: c convert io help this ai program to learn ram unit ear e il it section not in no converting

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.