Question: Write a method called stripComments that accepts a Scanner representing an input file containing a Java program as its parameter, reads that file, and then

Write a method called stripComments that accepts a Scanner representing an input file containing a Java program as its parameter, reads that file, and then prints the file’s text with all comments removed. A comment is any text on a line from // to the end of the line, and any text between /* and */ characters. For example, consider the following text:

import java.util.*; /* My program by Suzy Student */ public class Program { public static void main (String[] args) { System.out.println (

If the file contained this text, your program should output the following text:

import java.util.*; /* My program by Suzy Student */ public class Program

import java.util.*; /* My program by Suzy Student */ public class Program { public static void main (String[] args) { System.out.println ("Hello, world!"); // a println public static /* Hello there */ void foo () { System.out.println ("Goodbye!"); // comment here } /* * /

Step by Step Solution

3.49 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public static void stripComments Scanner input throws File... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!