Advertisement
Guest User

Untitled

a guest
May 30th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /**
  7.  *
  8.  * @author Админ
  9.  */
  10. import java.io.*;
  11.  
  12. public class NewClass {
  13.     public static void main(String[] args) {
  14.         if(args.length != 2) {
  15.             System.out.println("Wrong input");
  16.             return; //вариант1 и продолжить.
  17.         }
  18.         try {
  19.             StreamTokenizer in = new StreamTokenizer(new FileInputStream(args[0]));
  20.             in.nextToken();
  21.             int length = (int)in.nval;
  22.             double sum = 0.0; //не нужно созавать массив
  23.             for(int i = 0; i < length; i++,in.nextToken())
  24.                 sum +=in.nval;
  25.             PrintWriter out = new PrintWriter(new FileWriter(args[1]));
  26.             out.print(sum);
  27.             out.close();
  28.         } catch(Exception exc) {
  29.             System.out.println("" + exc);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement