answersLogoWhite

0


Best Answer

Add the five numbers; divide the result by 5.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you find the average of 5 numbers using static method in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the preferred method of using a lint static Compass when reading magnet Azimuths?

center hold


Why a static member method can access only static members in java?

Because, the keyword static signifies the fact that the method or variable that is qualified using the static keyword is not attached to any object of the class. Therefore we cannot instantiate the class and use the object to reference to access it. The only option we have is to use the class name to directly access them


Will JVM execute static methods by default like static variables in java?

No. Static methods are invoked by using the name of the class instead of the name of an instance of a class. Example: public class Test { public static void methodA { // do something ... } public void methodB { // do something else ... } } A program could use methodA by simply calling it using the class name: // call the static method Test.methodA(); To use methodB(), a program would have to first create an instance of the class then call the method: // call the non-static method Test t = new Test(); t.methodB(); Note that you can call methodA from the instance: // call the static method Test t = new Test(); t.methodA(); However, this is considered bad practice. And you cannot call methodB at all using the class name: // can't do this - compile error Test.methodB();


Static variable and static methods in java?

== == Static method cannot be overwritten because it belongs to the class and not to the ObjectIf you're asking about overriding or overloading, then yes. Static methods can be overridden and overloaded just like any other methods.


How do you sum up numbers from 1 to n?

import java.util.Scanner;public class average {static int i=0;static double sum = 0;static double average = 0;public static double calcSum(double sum){double count;Scanner input = new Scanner(System.in);while(i < 5){count = input.nextDouble();sum = sum + count;i++;}return sum;}public static double calcAverage(double average){double sum = calcSum(sum);average = calcSum(sum) / 5;return average;}public static void main(String[] args) {System.out.println("Please enter 5 numbers.");System.out.println("Sum is: "+calcSum(sum));System.out.println("Average is: "+calcAverage(average));}}

Related questions

Tell about static method?

in java a method is said to be static if 'static 'keyword is used before the method name . foe ex.- static void show(){ ........ } this method has the following property-- 1. it can invoke only a static method. 2. it can't be reffered using keyword 'this','super'. 3.static method can access only a STATIC MEMBER VARIABLE or STATIC CLASS VARIABLE . 4. there should not be static &amp; non static version of a nethod in a class . 5.static method can be used before the creation of d object of dt class.


How do you convert numbers into words using java?

Using toString() method


How do you get the sum of two numbers?

The best method is to add the numbers, using arithmetic.


How do you calculate rainfall using the thiessen polygon method?

Thiessen Polygon method is a weighted average mean method used to calculate average rainfall. The catchment area is divided into subcatchments using the Thiessen polygon method.


What is the preferred method of using a lint static Compass when reading magnet Azimuths?

center hold


Do decimal numbers have factorials?

by using the Gamma method apparently...:)


Why a static member method can access only static members in java?

Because, the keyword static signifies the fact that the method or variable that is qualified using the static keyword is not attached to any object of the class. Therefore we cannot instantiate the class and use the object to reference to access it. The only option we have is to use the class name to directly access them


Will JVM execute static methods by default like static variables in java?

No. Static methods are invoked by using the name of the class instead of the name of an instance of a class. Example: public class Test { public static void methodA { // do something ... } public void methodB { // do something else ... } } A program could use methodA by simply calling it using the class name: // call the static method Test.methodA(); To use methodB(), a program would have to first create an instance of the class then call the method: // call the non-static method Test t = new Test(); t.methodB(); Note that you can call methodA from the instance: // call the static method Test t = new Test(); t.methodA(); However, this is considered bad practice. And you cannot call methodB at all using the class name: // can't do this - compile error Test.methodB();


What is a method of writing very large or very small numbers by using the powers of ten?

Scienctific method


How do you sum up numbers from 1 to n?

import java.util.Scanner;public class average {static int i=0;static double sum = 0;static double average = 0;public static double calcSum(double sum){double count;Scanner input = new Scanner(System.in);while(i < 5){count = input.nextDouble();sum = sum + count;i++;}return sum;}public static double calcAverage(double average){double sum = calcSum(sum);average = calcSum(sum) / 5;return average;}public static void main(String[] args) {System.out.println("Please enter 5 numbers.");System.out.println("Sum is: "+calcSum(sum));System.out.println("Average is: "+calcAverage(average));}}


Static variable and static methods in java?

== == Static method cannot be overwritten because it belongs to the class and not to the ObjectIf you're asking about overriding or overloading, then yes. Static methods can be overridden and overloaded just like any other methods.


Which one executed first static block or static methods in java?

Static Blocks are always executed first. A static block is executed when your class is charged but a static method is executed only when is called, therefor first the class is charged and then is executed a method.