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 9

Categories: Java

faltutech

Pursuing MCA from YMCA University, Faridabad

Leave a Reply

Your email address will not be published. Required fields are marked *

Read previous post:
Merge Two Arrays in Third Array in Java
Merge Two Arrays in Third Array in Java

[crayon-5a2bbac3a3200909009422/] output [crayon-5a2bbac3a320a757916745/] Compiled with JDK 9

Close