Advertisement
smgr

cassone.java

Jan 17th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Cassone {
  5.  
  6.     static double kmToMill(double km) {
  7.         double mill = km * 1.6;
  8.         return mill;
  9.     }
  10.  
  11.     public static void main(String[] args) {
  12.  
  13.  
  14.         try {
  15.             RandomAccessFile fileKi = new RandomAccessFile("szamok.txt", "rw");
  16.             Scanner bill = new Scanner(System.in);
  17.             double osszes = 0;
  18.             int db = 0;
  19.             while (true) {
  20.                 double szam = bill.nextDouble();
  21.                 if(szam == -1)
  22.                     break;
  23.                
  24.                 double mill = kmToMill(szam);
  25.                
  26.                 osszes += mill;
  27.                 db++;
  28.                
  29.                 System.out.println(mill + "\n");
  30.                 fileKi.writeBytes(mill + "\n");
  31.             }
  32.             System.out.println("átlag: " + osszes/db);
  33.             fileKi.close();
  34.         } catch(IOException e){
  35.             System.err.println(e);
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement