Created
April 29, 2020 19:52
-
-
Save singhrahuldps/e2fba3c63143d27c6839aba4e9e66985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Program to return average of numbers | |
public static double doAverage(ArrayList<Integer> marks) { | |
// double for more precision than Integer during division | |
double avg = 0.0; | |
for(int mark: marks) { | |
avg += mark; | |
} | |
// size() method returns the number of elements in array | |
avg = avg/marks.size(); | |
return avg; | |
} | |
public static void main(String[] args) { | |
ArrayList<Integer> marks = new ArrayList<>(List.of(95,96,98)); | |
// static methods can be accessed directly without creating a class object | |
// Here class name is Methods | |
double avg = Methods.doAverage(marks); | |
System.out.println(avg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment