KIT JAVA AND PYTHON_B7 java practice PROBLEM 1

Run Settings
LanguageJava
Language Version
Run Command
import java.util.Scanner; import static java.lang.System.*; import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(in); double n = scan.nextDouble(); double sum = 0; ArrayList<Double> xs = new ArrayList<Double>(); for (double i = 0; i < n; ++i) { double x = scan.nextDouble(); xs.add(x); sum += x; } out.println("Mean: " + sum / n); Collections.sort(xs); double h = n / 2; if (n % 2 == 0) { int hi = (int)h; out.println("Median: " + ((xs.get(hi) + xs.get(hi - 1)) / 2)); } else { int hi = (int)(h + 0.5); out.println("Median: " + xs.get(hi)); } int max = 0; int maxI = 0; for (int i = 0; i < n; ++i) { int memo = 0; for (int j = 0; j < n; ++j) { if (xs.get(i) == xs.get(j)) { ++memo; } } if (memo > max) { max = memo; maxI = i; } } out.println("Mode: " + xs.get(maxI)); } }
Editor Settings
Theme
Key bindings
Full width
Lines