Computer Science, asked by aadiidee13, 8 months ago

Write a program to take several line input from user and, read the lines and tell a. whether there is a comment line or not? b. If there is comment used in the program, is it single line or multi-line? c. Position/line number where comments are used. any programming language Hint: Use line break to count and specify position.

Answers

Answered by ayushbansal93
1

Answer:

sorry I didn't know

Explanation:

Mark as brainliest

Answered by dreamrob
0

Program in Java:

import java.util.*;

public class Main

{

public static void main(String[] args)

{

    Scanner Sc = new Scanner(System.in);

       String s;

       System.out.print("Enter several lines : ");

       s = Sc.nextLine();

       String line[] = s.split("[.?!]");

       int single = 0 , multi = 0;

       for(int i = 0 ; i < line.length ; i++)

       {

           for(int j = 0 ; j < line[i].length()-1 ; j++)

           {

               char ch1 = line[i].charAt(j);

               char ch2 = line[i].charAt(j+1);

               if(ch1 == '/' && ch2 == '/')

               {

                   System.out.println("Single line comment");

                   System.out.println("Line number : " + (i+1));

                   single++;

               }

               if(ch1 == '/' && ch2 == '*')

               {

                   System.out.println("Multi line comment");

                   System.out.println("Line number : " + (i+1));

                   multi++;

               }

           }

       }

       if(single == 0 && multi == 0)

       {

           System.out.print("There is no comment line");

       }

       else

       {

           System.out.println("Total single line comments : " + single);

           System.out.println("Total multi line comments : " + multi);

           System.out.println("Total comment lines : " + (single + multi));

       }

}

}

Similar questions