-
Title Description:
-
There are several students in the class, giving the age of each student (whole number), the average age of all students in the class, and the retention of two decimal places.
-
Input:
-
The first line has an integer n (1<= n <= 100) that represents the number of students. The next n rows have 1 integers per line, with values from 15 to 25.
-
Output:
-
There may be multiple sets of test data, for each set of data,
The output row, which contains a floating-point number, is reserved to two digits after the decimal point for the required average age.
-
Sample input:
-
21817
-
Sample output:
-
17.50
-
Tips:
-
To output floating-point numbers, double-precision digits after the decimal 2 digits, you can use the following form:
printf ("%.2f", num);
-
-
Source:
-
-
-
Import Java.text.decimalformat;import Java.text.format;import Java.util.Scanner; public class main{public static void Main (String args[]) {int []age=new int[100]; int people; int i,j,k; int sum; float average; Scanner cin=new Scanner (system.in); DecimalFormat myformat=new DecimalFormat ("#.00"); while (Cin.hasnext ()) {people=cin.nextint (); sum=0; for (i=0;i<people;i++) {age[i]=cin.nextint (); Sum+=age[i]; } average=sum/(float) people; System.out.println (Myformat.format (sum/people)); System.out.println (Myformat.format (average)); }}}/************************************************************** problem:1128 User:carvin Language:java result:accepted time:790 Ms memory:73052 kb****************************************************************/
Topic 1128: Finding the average age