Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-conversion Calculate the Sum of three Numbers

Related Tutorials


 
 

Share on Google+Share on Google+

Calculate the Sum of three Numbers

Advertisement
This is simple java programming tutorial . In this section you will learn how to calculate the sum of three numbers by using three static variables.

Calculate the Sum of Three Numbers

     

This is simple java programming tutorial . In this section you will learn how to calculate the sum of three numbers by using three static variables. 

Description of this program:

In this section we will see how to calculate three integer number . First of all define class name "StaticSum". For this we have defined three static variables of type int.  To assign the value of the numbers define a method main. Remember we are overloading the main method. This method will take three arguments.  The values will be added in the Addition method which we have declared in our program. Now call the main method. To get the values of the three numbers call the overloaded method main() inside main() method. To add those values call the Addition method which will return the integer value and the value will be displayed to the user by using the println() method of the System class.

Here is the code of this program

class StaticSum 
{
  public static int width;
  public static int height;
  public static int length;

  public static void main(int width1, int height1, int length1
  {
  width= width1;
  height=height1;
  length=length1;
  }
  public int Addition()
  {
  return(width+height+length);
  }
  public static void main(String arg[])
  {
  StaticSum staticSum = new StaticSum();
  StaticSum.main(12,14,15);
  int i= staticSum.Addition();
  System.out.println("value is="+ i);
  }
}

Download this Example

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



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 25, 2008

Related Tutorials

Discuss: Calculate the Sum of three Numbers   View All Comments

Post your Comment


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