Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Scanner;
  3.  
  4. public class HW01_1 {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner jin = new Scanner(System.in);
  8.         checkTxtSize(jin.nextLine());
  9.         jin.close();
  10.     }
  11.  
  12.     private static void checkTxtSize(String input) {
  13.         File[] files = new File(input).listFiles();
  14.         double size = 0;
  15.         int count = 0;
  16.         for (int i = 0; i < files.length; i++) {
  17.             if(files[i].isFile()&&files[i].getName().substring(files[i].getName().lastIndexOf(".")+1).equals("txt")){
  18.                 size += files[i].length();
  19.                 count++;
  20.             }
  21.         }
  22.         System.out.println(String.format("%.2f", size/count));
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement