Java

Average of all array elements Using Java

[crayon-5a2bbaafa0f7c577467936/] Output Average is : 4.857142857142857 Discussion To limit the digits after decimal use : ‘DecimalFormat’ Class or System.out.format() or String.format or System.out.printf() e.g. DecimalFormat newDecimalFormat = new DecimalFormat(“#:00”); newnumber = newDecimalFormat.format(whateverYourNumberIs); It will give you 4.85 according for above result Also you need to import java.text.DecimalFormat. Compiled with JDK Read more…

By faltutech, ago