Advertisement
fensa08

#OS LAB1/4

Mar 23rd, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. #OS LAB1/4 made by Fensa08
  2. import java.io.*;
  3.         import java.util.ArrayList;
  4.         import java.util.Collections;
  5.         import java.util.Scanner;
  6.  
  7. public class HW01_4 {
  8.    
  9.    
  10.     public static void main(String args[]) throws IOException {
  11.  
  12.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  13.         FileReader file = new FileReader("rezultati.csv");
  14.         String pole = in.readLine();
  15.         BufferedReader bu = new BufferedReader(file);
  16.         ArrayList<String> proseci = new ArrayList<>();
  17.         String line = null;
  18.         int index=0;
  19.         float prosek = 0;
  20.         float prosekK = 0;
  21.         int colLen = 1;
  22.         line = bu.readLine();
  23.         String []pom = line.split(",");
  24.  
  25.         //Cita prv red, bara indeks na barana kolona
  26.         for(int i = 0; i < pom.length;i++){
  27.             if(pom[i].equals(pole)){
  28.                 index = i;
  29.             }
  30.         }
  31.  
  32.         while((line = bu.readLine()) != null){
  33.             pom = line.split(",");
  34.             prosek = 0;
  35.             for(int i = 1; i < pom.length;i++){
  36.                 if(i == index){
  37.                     prosekK += Integer.parseInt(pom[i]);
  38.                     colLen++; // go dodava na prosekot za kolona
  39.                 }
  40.                 prosek += Integer.parseInt(pom[i]);
  41.             }
  42.             String linija = "Prosekot na " + pom[0] + " e: " + (prosek/(pom.length-1));
  43.             proseci.add(linija);
  44.         }
  45.         String linija = "Prosekot za "  + pole + " e: " + (prosekK/(colLen-1));
  46.         proseci.add(linija);
  47.  
  48.  
  49.         //Printanje podatok
  50.         for(String i : proseci){
  51.             System.out.println(i);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement