How to make java program which computes average of three numbers

In java,Programs are built from the classes.From a class definition,you can create any number of objects.Here is the code of java program which computers average of three numbers.

//1.0 Average of three numbers

Class Avg
{
 Public static void main(String args[])

{
 Int m1=10,m2=20,m3=30;
 float avg;

 avg=(m1+m2+m3)/3;

 System.out.println(avg);
}

}

     Here,The First Line "//1.0 Average of three numbers" is the description of these java program.The second Line,"Class Avg" declares the class.The keyword "Avg" is java identifier which is the name of the class.After it we have to define this.A Definition starts with "{" and ends with "}" .

    The third line "Public static void main(String args[])" It defines the method named "main".Every JAVA Program must contain 'main()' Method.At this point java interpreter starts executing the program.

    Next line,"Int m1=10,m2=20,m3=30;" is the numbers of which average is to be calculated in this program."float avg;" is the command which executes the program for calculating the average.

  "avg=(m1+m2+m3)/3;" is the formula of calculating average of the given numbers.Next line prints the averrage on Computer screen.

   Progrram will run  smoothly if it is typed correctly.

Comments

Popular posts from this blog

Why Businesses Should Use Digital Marketing Services?

Optimize your Blogger Title Tag For Better Search Ranking

How to Add/Install Commentluv Plugin To Blogger