Overloaded methods 1 Answer(s) 3 years and 2 months ago
Posted in : Java Beginners
Write two overloaded methods that return the average of an array with the following headers: a) public static int average(int[] array) b) public static double average(double[] array)
View Answers
March 24, 2010 at 12:37 PM
Hi Friend,
Try the following code:
class Overloading{ static int sum1=0; static double sum2=0.0; public static int average(int[] array){ int len=array.length; for(int i=0;i<len;i++){ sum1+=array[i]; }
int average=sum1/len; return average; } public static double average(double[] array){ int len=array.length; for(int i=0;i<len;i++){ sum2+=array[i]; }
double average=sum2/len; return average; } public static void main(String[]args){ int arr1[]={1,2,3,4,5}; double arr2[]={1.5,2.5,3.5,4.5,5.0};
int average1=Overloading.average(arr1); System.out.println("Average from Method1: "+average1); double average2=Overloading.average(arr2); System.out.println("Average from Method2: "+average2);
} }
Thanks
Related Pages:
Java overloaded methods
Java overloaded methods Can overloadedmethods can also be overridden
Overloaded methods - Java Beginners Overloaded methods Write two overloadedmethods that return the average of an array with the following headers:
a) public static int average(int[] array)
b) public static double average(double[] array)
Hi Friend
Can a main method be overloaded?
Can a main method be overloaded? Hi,
Can a main method be overloaded?
thanks,
Hi,
Yes, In Java program we could having multiple number of main() methods with different Signature and implementation in the class
Methods - OOP
is overloaded when there are two or more methods
by the same name in a class. At first...
Java NotesMethods - OOP
Static methods
If your method doesn't use... utility methods
and main(...), you should probably not be using static methods
methods
methods PrintStream class has two formatting methods,what
methods
methods PrintStream class has two formatting methods,what
methods
methods PrintStream class has two formatting methods,what
static methods
static methods why static methods cannot read or write the instance variables
Agile methods
Agile methods Why use Agile methods?
This methods focus on shorter iterations, in which the software is brought to a releasable level of quality fairly often, usually somewhere between weekly and monthly. Short
Class, Object and Methods
Class, Object and Methods
 ...,
object and it's methods. This program uses the several values of several defined... is a software
bundle of variables and related methods of the special class
native methods
native methods what is native methods in java?
A native method is a method that is implemented in a language other than Java.
The Java native method is a great way to gain and merge the power of C or C++ programming
Cookie methods in jsp
Cookie methods in jsp Define cookie methods in jsp ?
Cookie methods :
clone()
getComment()
getDomain()
getMaxAge()
getName()
getPath()
getSecure()
getValue()
getSecure()
getVersion
java object class methods
java object class methods What are the methods in Object class? There are lots of methods in object class.
the list of some methods are as-
clone
equals
wait
finalize
getClass
hashCode
notify
notifyAll
GET and POST methods
GET and POST methods What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods
factory methods in java?
factory methods in java? what are factory methods in java?
Hi Friend,
Factory methods are static methods that return an instance of the native class like Pattern.compile(), Calendar.getInstance
abstract methods in java
abstract methods in java what is abstract methods in java.give better examples for understanding
Hi Friend,
Please visit the following link:
http://www.roseindia.net/java/master-java/abstract-class.shtml
Thanks
to create a java class and methods
it with methods that can be used to reverse a list & append two lists.Also to comment on whether the dsign ade has led to make methods for append
Callback Methods
Callback Methods
Callbacks methods are the way of managing life cycle of
an instance. Callback methods are generally used by containers. The methods are
called at specific time
Methods in Jsp - Development process Methods in Jsp
Hi, My interviewer said we should declare & define all methods inside _jspService() method only. is it correct . Thanks Prakash Hi Friend,
Yes, all the methods should be declared and defined
looping through a list of methods
looping through a list of methods I have a number of methods that do the almost same thing:
public void setColorRed (int colorvalue);
public...);
Is there a way to place these methods in a list and then call each one from
methods in the applet - Applet methods in the applet import java.awt.*;
import java.applet.Applet... provides the Applet class with default implementation for all the applet methods. You can implement these methods in the applet class when you want to override
Methods in Java - Java Beginners Methods in Java Hello.
Currently i am involved in a group project and we have each been given a specific part of code to create our joint programI however have been given the job to create a method for storing and recalling 5
Java :Thread Methods
Java :Thread Methods
This section explains methods of Thread class.
Thread Methods :
Thread class provides many method to handle different thread... and allow other
threads the temporal executing thread object.
Some other methods
what is class methods in objective c
what is class methods in objective c What is class methods in objective c? Explain the class method of objective c with the help of an example
list of predeined methods and use java
list of predeined methods and use java I need list of predefined methods in java like reverse,compare,tostring, etc
what is class methods in objective c
what is class methods in objective c What is class methods in objective c? Explain the class method of objective c with the help of an example
What are the methods in Object? - Java Beginners
What are the methods in Object? Hi,
What are the methods in Object? Give example of methods in Object.
Thanks
Hello,
There are lot of method in object class some of are as follows
toString();
wait
RIAs Methods And Techniques
RIAs Methods And Techniques
JavaScript
It is the first major client side language technology that has the
ability to run code and installed on several major of web clients. Earlier its
uses were relatively limited but the development
some methods not working on firefox and chrome
some methods not working on firefox and chrome why some of javascript methods are not working on firefox and chrome? ex : createElement().
Please help me to solve this problem.
adv thanx