import java.util.*; interface Sum { void add(Number x); } class FloatSum implements Sum { float val = 0; public void add(Number x) { val += ((Float)x).floatValue(); } public String toString() { return String.valueOf(val); } } class IntSum implements Sum { int val = 0; public void add(Number x) { val += ((Integer)x).intValue(); } public String toString() { return String.valueOf(val); } } class LLOld { Number data; LLOld next; LLOld(Number d, LLOld n) { data = d; next = n; } Sum printAndSum(Sum summer) { System.out.println(data); summer.add(data); if (next != null) next.printAndSum(summer); return summer; } public static void main(String[] args) { LLOld flist = null; LLOld ilist = null; Scanner in = new Scanner(System.in); while (in.hasNextDouble()) { double d = in.nextDouble(); flist = new LLOld(Float.valueOf((float)d), flist); ilist = new LLOld(Integer.valueOf((int)d), ilist); } System.out.println("Floating sum: " + flist.printAndSum(new FloatSum()) + "\n"); System.out.println("Integer sum: " + ilist.printAndSum(new IntSum()) + "\n"); } }