Pagini recente » Cod sursa (job #2520325) | Cod sursa (job #2371441) | Cod sursa (job #2512951) | Cod sursa (job #2398868) | Cod sursa (job #2095719)
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static ArrayList<Integer> getItems(ArrayList<Integer> integers) throws FileNotFoundException {
File file = new File("adunare.in");
Scanner scanner = new Scanner(file);
while (scanner.hasNext()) {
if (scanner.hasNextInt()) {
integers.add(scanner.nextInt());
} else {
scanner.next();
}
}
return (ArrayList<Integer>) integers;
}
public static void computeArray(ArrayList<Integer> integers) throws Exception {
int sum = 0;
for(Integer inta : integers){
sum+=inta;
}
Writer writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("adunare.out"), "utf-8"));
writer.write(String.valueOf(sum));
} catch (IOException ex) {
} finally {
try {writer.close();} catch (Exception ex) {}
}
}
public static void main(String[] args) throws Exception {
computeArray(getItems(new ArrayList<Integer>()));
}
}