CS506 assignment 1 solution fall 2011
SAVE THIS FILE IN .JAVA FORMAT import java.io.*; import java.util.*; import javax.swing.*; public class assignment1{ public static void main( String args[] ){ try{ FileReader fr = null; BufferedReader br = null; fr = new FileReader ("input.txt"); br = new BufferedReader (fr); String line = br.readLine(); double sum =0 ; while (line != null) { double num = Double.parseDouble(line); sum += num; line = br.readLine(); } JOptionPane.showMessageDialog(null, "Sum = " + sum); br.close(); fr.close(); } catch(NumberFormatException nfEx) { System.out.println(nfEx); } catch(FileNotFoundException fnfEx){ System.out.println(fnfEx); } catch(IOException ioEx){ System.out.println(ioEx); } } }
0 comments:
Post a Comment