remove comment
来源:互联网 发布:java选择题及答案 编辑:程序博客网 时间:2024/05/24 06:47
public class RemoveComments {public static void main(String[] args) {String str = "e//b/*c*/d\nefee";System.out.print(removeComments(str));}static String removeComments(String prgm) {int n = prgm.length();StringBuilder res = new StringBuilder();// Flags to indicate that single line and multpile line comments. From// have started or not.boolean s_cmt = false;boolean m_cmt = false;// Traverse the given programfor (int i = 0; i < n; i++) {// If single line comment flag is on, then check for end of itif (s_cmt == true && prgm.charAt(i) == '\n')s_cmt = false;// If multiple line comment is on, then check for end of it.else if (m_cmt == true && prgm.charAt(i) == '*' && prgm.charAt(i + 1) == '/') {m_cmt = false;i++;}// If this character is in a comment, ignore itelse if (s_cmt || m_cmt) {continue;}// Check for beginning of comments and set the approproate flagselse if (prgm.charAt(i) == '/' && prgm.charAt(i + 1) == '/') {s_cmt = true;i++;} else if (prgm.charAt(i) == '/' && prgm.charAt(i + 1) == '*') {m_cmt = true;i++;}// If current character is a non-comment character, append it to reselseres.append(prgm.charAt(i));}return res.toString();}}
0 0
- remove comment
- Comment
- comment
- comment
- comment.c
- simple comment
- #pragma comment
- #pragma comment()
- 查看comment
- #pragma comment
- #pragma comment
- #pragma comment
- PHP comment
- #pragma comment
- pragma comment
- #pragma comment
- COMMENT Command
- #pragma comment
- PAT-A 1020. Tree Traversals
- Java反射机制详解
- jQuery中的each方法
- C常用转义字符
- Java Basics Part 2/20 - Environment Setup
- remove comment
- LeetCode | Swap Nodes in Pairs
- java基础知识
- 继承存在时的程序执行流程
- AsynTask异步任务的使用(再也忘不了了)
- 大小堆的实现,删除,添加
- 老九门 明信片 周边 海报 赵丽颖 陈伟霆 马克杯
- C语言程序设计谭浩强版 七
- unity使用的第三方工具