Pagini recente » Cod sursa (job #953708) | Cod sursa (job #1040708) | Cod sursa (job #953820) | Cod sursa (job #2050301) | Cod sursa (job #1651240)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package sum;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author DelOvi
*/
public class Sum {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader("adunare.in"));
int sum=0;
String line;
while((line=br.readLine())!=null){
int x=Integer.parseInt(line);
sum+=x;
}
br.close();
FileWriter fw = new FileWriter("adunare.out");
fw.write(sum);
fw.close();
}
catch (FileNotFoundException e) {
System.out.println("File not Found!");
}
catch(NumberFormatException e){
System.out.println("Exception at conversion String-");
}
catch (IOException ex) {
Logger.getLogger(Sum.class.getName()).log(Level.SEVERE, null, ex);
}
}
}