Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Bound Types
import java.util.*; import java.lang.*; class Stats<T extends Number>{ T[] nums; Stats(T[] o) { nums = o; } double average(){ double sum = 0.0; for ( int i = 0; i < nums.length; i++) sum += nums[i].doubleValue(); return sum / nums.length; } } class Rextester { public static void main(String args[]) { Integer inums[] = { 1, 2, 3, 4, 5}; Stats<Integer> iOb = new Stats<>(inums); double av1 = iOb.average(); System.out.println("The average is: "+av1); Double dnums[] = { 1.1, 2.2, 3.3, 4.4, 5.5}; Stats<Double> dOb = new Stats<>(dnums); double av2 = dOb.average(); System.out.println("The average is: "+av2); } }
run
|
edit
|
history
|
help
0
2
pattern of the day (code formatting fixed)
Firstproject
1a
add2
hondaa11
preincrement1
Человечки
toStringMethodinJava
jb11.0 threads tick tock