Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.lang.String;
- public class Main {
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- System.out.println("Введите код на языке C#: ");
- String[] readCode = readLinesFromConsole();
- deleteComment(readCode);
- }
- public static int deleteComment (String[] code) {
- String[] finishCode = new String[code.length];
- int startLongComment = 0;
- for (int i = 0; i < code.length; i++) {
- finishCode[i] = "";
- for (int j = 0; j < code[i].length() - 1; j++) {
- if (startLongComment == 1) {
- if (code[i].charAt(j) == '*' && code[i].charAt(j + 1) == '/') {
- j++;
- startLongComment = 0;
- }
- } else {
- if (code[i].charAt(j) == '/' && code[i].charAt(j + 1) == '*') {
- startLongComment++;
- } else if (code[i].charAt(j) == '/' && code[i].charAt(j + 1) == '/') {
- break;
- } else {
- finishCode[i] += code[i].charAt(j);
- }
- if (j == code[i].length() - 2 && code[i].charAt(j + 1) != '*') {
- finishCode[i] += code[i].charAt(j + 1);
- }
- }
- }
- }
- writeFinishCode(finishCode);
- return 1;
- }
- public static int writeFinishCode (String[] code) {
- for (int i = 0; i < code.length - 1; i++) {
- if (code[i] == "") {
- } else {
- System.out.print(code[i] + "\n");
- }
- }
- System.out.print(code[code.length - 1]);
- return 1;
- }
- public static String[] readLinesFromConsole() {
- Scanner scanner = new Scanner(System.in);
- List<String> lines = new ArrayList<>();
- String line = scanner.nextLine();
- lines.add(line);
- while (scanner.hasNextLine()) {
- String lineLast = line;
- line = scanner.nextLine();
- if ((line == null || line.trim().length() == 0) && (lineLast == null || lineLast.trim().length() == 0))
- break;
- lines.add(line);
- }
- return lines.toArray(new String[0]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement