Home Java Java-conversion Calculate the Sum of three Numbers



Calculate the Sum of three Numbers
Posted on: June 25, 2008 at 12:00 AM
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

Related Tags for Calculate the Sum of three Numbers:
javacprogrammingvariablesstaticiovariablenumberstutorialnumbersumusingriathissimpleprogramtolearnrameareilsectionvarulimincalstacalcmmincacalculateminjeshowhrprotorssueeatlateisllmpleaarstatsimvatutorssrithavstabablatipleplprmionogro


More Tutorials from this section

Ask Questions?    Discuss: Calculate the Sum of three Numbers   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.