题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.text.DateFormat; import java.text.DecimalFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; import static java.util.Arrays.*; import static java.util.stream.Stream.*; public class Main { public static void main(String[] args) throws IOException { testTh(); } private static void testTh() throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str; while ((str = bf.readLine()) != null) { str = bf.readLine(); String[] s = str.split(" "); int[] temp = new int[s.length]; int i = 0; int count = 0; for (String s1 : s) { int parseInt = Integer.parseInt(s1); if (parseInt < 0) { count++; } else if (parseInt == 0) { continue; } else { temp[i] = parseInt; i++; } } int res = 0; int flag = 0; for (int j = 0; j < temp.length; j++) { if (temp[j] == 0)break; res = res + temp[j]; flag++; } if (flag == 0) { System.out.println(count + " " + "0.0"); } else { double avg = (double) res / flag; DecimalFormat dateFormat = new DecimalFormat("#0.0"); System.out.println(count + " " + dateFormat.format(avg)); } } } }