Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class PB {
  4.     public static void main(String[] args) throws FileNotFoundException {
  5.         Scanner io = new Scanner(new File("pe.txt"));
  6.         Stack<Character> st = new Stack<Character>();
  7.         int comment1 = 0;
  8.         int comment2 = 0;
  9.         while(io.hasNextLine())
  10.         {
  11.             String line = io.nextLine();
  12.             for(int i=0;i<line.length();i++)
  13.             {
  14.                 char p = line.charAt(i);
  15.                 String p2 = (i==line.length()-1)? line.charAt(i)+"" : line.charAt(i)+""+line.charAt(i+1)+"" ;
  16.                
  17.                 if(st.isEmpty()==true&&p2.equals("/*"))
  18.                     st.push('*');
  19.                 else if(!st.isEmpty()&&p2.equals("*/"))
  20.  
  21.                     if(st.peek()=='*'&&p2.equals("*/")){
  22.                         st.pop();
  23.                         comment2++;
  24.                     }
  25.                 else if(st.isEmpty()==true&&p2.equals("//"))
  26.                     st.push('/');
  27.                 else if(!st.isEmpty()&&i==(line.length()-1))
  28.                     if(st.peek()=='/'&&i==(line.length()-1))
  29.                     {
  30.                         st.pop();
  31.                         comment1++;
  32.                     }
  33.                 else if(st.isEmpty()==true && p=='"')
  34.                     st.push('"');
  35.                 else if(!st.isEmpty()&&p=='"')
  36.                     if(st.peek()=='"'&&p=='"')
  37.                         st.pop();
  38.                 else if(st.isEmpty()==true && p=='\'')
  39.                     st.push('\'');
  40.                 else if(!st.isEmpty()&&p=='\'')
  41.                     if( st.peek()=='\''&&p=='\'')
  42.                         st.pop();
  43.             }
  44.            
  45.         }
  46.         System.out.println(comment1);
  47.         System.out.println(comment2);
  48.        
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement