Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- public class HW01_4 {
- public static void main(String[] args) throws IOException {
- BufferedReader br;
- try {
- br = new BufferedReader(new InputStreamReader(new FileInputStream("rezultati.csv")));
- } catch (FileNotFoundException e) {
- System.out.println("Ne e pronajden takov fajl!");
- return;
- }
- BufferedWriter bw;
- try {
- bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("rezultati.tsv")));
- } catch (FileNotFoundException e) {
- System.out.println("Ne e mozno da se otvori toj fajl!");
- return;
- }
- String novRed = br.readLine();
- String oceni[] = novRed.split(",");
- int brOceni = oceni.length-1;
- int zbirOceni[] = new int[novRed.length()];
- int vkStudenti = 0;
- bw.write(novRed.replace(",", "\t")+"\n");
- while ((novRed = br.readLine()) != null){
- String oceniUcenik[] = novRed.split(",");
- int zbir = 0;
- vkStudenti++;
- for (int i=1; i<oceniUcenik.length; i++){
- zbir += Integer.parseInt(oceniUcenik[i]);
- zbirOceni[i] += Integer.parseInt(oceniUcenik[i]);
- }
- System.out.println("Studentot: "+oceniUcenik[0]+" ima prosek: "+(zbir*1.0/brOceni));
- bw.write(novRed.replace(",", "\t")+"\n");
- }
- for (int i=1; i<oceni.length; i++)
- System.out.println("Po predmetot: "+oceni[i]+" prosecnata ocena e: "+(zbirOceni[i]*1.0/vkStudenti));
- br.close();
- bw.flush();
- bw.close();
- }
- }
Add Comment
Please, Sign In to add comment