Check if a given string is a comment or not | Java program for the above approach ; Function to check if the given string is a comment or not ; If two continuous slashes preceeds the comment ; Driver Code ; Given string ; Function call to check whether then given string is a comment or not
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void isComment ( String S ) { char line [ ] = S . toCharArray ( ) ; if ( line [ 0 ] == ' / ' && line [ 1 ] == ' / ' ) { System . out . println ( " It ▁ is ▁ a ▁ single - line ▁ comment " ) ; return ; } if ( line [ 0 ] == ' / ' && line [ 1 ] == ' * ' && line [ line . length - 2 ] == ' * ' && line [ line . length - 1 ] == ' / ' ) { System . out . println ( " It ▁ is ▁ a ▁ multi - line ▁ comment " ) ; return ; } System . out . println ( " It ▁ is ▁ not ▁ a ▁ comment " ) ; } public static void main ( String [ ] args ) { String line = " GeeksForGeeks ▁ GeeksForGeeks " ; isComment ( line ) ; } }