Strip Line Comments
Given lines of pretend source code, remove any // line comment from each line (everything from the first // to the end of the line), trim trailing spaces, and print the lines that still have content.
Assume // never appears inside a string literal.
Input: the first line is an integer N; then N lines of text.
Output: for each line, the code part with its // comment removed and trailing spaces trimmed — but skip lines that become empty.
3 int x = 5; // set x // full comment line y = x + 1;
int x = 5; y = x + 1;
- 1 <= N <= 100
- each line has at most 200 characters
Hint 1
line.indexOf("//") finds the comment start (or -1 if none).
Hint 2
line.substring(0, idx) keeps only the code part.
Hint 3
String.stripTrailing() removes trailing spaces; skip the line if it is then empty.
For each line, cut everything from the first // onward, then strip trailing whitespace. A line that was entirely a comment becomes empty and is skipped, so only real code lines are printed.