Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) throws IOException {
  6.         Scanner sc = new Scanner(new File("log.txt"));
  7.         int totalSearches = 0;
  8.         int totalHops = 0;
  9.         String trLine = "";
  10.         int hist[] = new int[30];
  11.  
  12.  
  13.         while(sc.hasNextLine()){
  14.             trLine = sc.nextLine();
  15.             System.out.println(trLine);
  16.             String ip = "";
  17.             if(trLine == null){
  18.                 break;
  19.             }
  20.             if(trLine.substring(0,9).equals("traceroute")){
  21.                 System.out.println(totalSearches);
  22.                 totalSearches++;
  23.                 ip = trLine.substring(trLine.indexOf("(") + 1, trLine.indexOf(")"));
  24.             } else {
  25.                 if(trLine.indexOf(ip) > 0){
  26.                     int hops = Integer.parseInt(trLine.substring(0, trLine.indexOf(" ")));
  27.                     totalHops += hops;
  28.                     hist[hops]++;
  29.  
  30.                 }
  31.             }
  32.         }
  33.         sc.close();
  34.  
  35.         System.out.println(totalSearches);
  36.         System.out.println(totalHops);
  37.  
  38.         for(int i = 0; i < 30; i++) {
  39.             System.out.println(hist[i]);
  40.         }
  41.  
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement