/****************************************************************************** * This program computes the sum of a list of float values on STDIN. * * Copyright © 2016 Richard Lesh. All rights reserved. *****************************************************************************/ import org.pureprogrammer.Utils; public class TotalFilterFP { public static void main(String[] args) { String line; double d; double total = 0; while ((line = Utils.getline()) != null) { line = Utils.trim(line); try { d = Double.parseDouble(line); total += d; } catch (Exception ex) { if (Utils.cpLength(line) > 0) { System.out.println(Utils.join("", "Can't parse input: ", line)); } } } System.out.println(Utils.format("{0:g}", total)); } }