Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws IOException {
- Scanner sc = new Scanner(new File("log.txt"));
- int totalSearches = 0;
- int totalHops = 0;
- String trLine = "";
- int hist[] = new int[30];
- while(sc.hasNextLine()){
- trLine = sc.nextLine();
- System.out.println(trLine);
- String ip = "";
- if(trLine == null){
- break;
- }
- if(trLine.substring(0,9).equals("traceroute")){
- System.out.println(totalSearches);
- totalSearches++;
- ip = trLine.substring(trLine.indexOf("(") + 1, trLine.indexOf(")"));
- } else {
- if(trLine.indexOf(ip) > 0){
- int hops = Integer.parseInt(trLine.substring(0, trLine.indexOf(" ")));
- totalHops += hops;
- hist[hops]++;
- }
- }
- }
- sc.close();
- System.out.println(totalSearches);
- System.out.println(totalHops);
- for(int i = 0; i < 30; i++) {
- System.out.println(hist[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement