Guest User

Untitled

a guest
May 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. public static void stripComments(Scanner in) {
  2.     String output=""; // iki tip comment oldugundan dosyayi iki kere islemeye karar verdim
  3.                       // output bunun icin tanimlandi
  4.     // "//" ile baslayan commentler icin
  5.     while (in.hasNextLine()) {
  6.         String line = in.nextLine();
  7.         int commentStart=line.indexOf("//"); // Comment'in basladigi yeri buluyoruz
  8.         if (commentStart == -1) // eger comment yoksa indexOf -1 dondurur
  9.             output+=line+"\n";
  10.         else // eger comment varsa
  11.             output+=line.substring(0,commentStart)+"\n";
  12.     }
  13.     while (output.indexOf("/*") != -1) {
  14.         String beforeComment = output.substring(0,output.indexOf("/*"));
  15.         String afterComment  = output.substring(output.indexOf("*/")+2);
  16.         output=beforeComment+afterComment;
  17.     }
  18.     System.out.print(output);
  19. }
Add Comment
Please, Sign In to add comment