Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void stripComments(Scanner input) {
- String s = "";
- while( input.hasNextLine() ) {
- s += input.nextLine() + "\n";
- }
- while( s.indexOf("/*")>=0 ) {
- int first = s.indexOf("/*");
- int second = s.indexOf("*/");
- s = s.substring(0, first) + s.substring(second+2);
- }
- while( s.indexOf("//") >= 0 ) {
- int first = s.indexOf("//");
- String f = s.substring(0, first);
- String g = s.substring(first+2);
- int a = g.indexOf("\n");
- int second = f.length() + a;
- s = s.substring(0, first) + s.substring(second+2);
- }
- System.out.print(s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement