Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I\'ve been having a hell of a time with this problem: Write a method call

ID: 3540257 • Letter: H

Question

Hello,


I've been having a hell of a time with this problem:


Write a method called stripHtmlTags that accepts a Scanner representing an input file containing an HTML web page as its parameter, then reads that file and prints the file's text with all HTML tags removed. A tag is any text between the characters < and > . For example, consider the following text:

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

You may assume that the file is a well-formed HTML document and that there are no < or > characters inside tags.


I've tried some of the solutions that a few others have posted on this site, but they're still not producing the correct output. Mainly, they're missing the spaces found after the first and second paragraphs.


Any help would be appreciated!


-B

Explanation / Answer

please rate - thanks


tested on practice it


import java.util.*;
import java.io.*;
public class stripHtmlTags
{public static void main(String[] args)throws FileNotFoundException
{
Scanner input=new Scanner(new File("html.txt"));
stripHtmlTags(input);
}




public static void stripHtmlTags(Scanner input)
{String buffer;
boolean html=false,prev=false;
int i;
while(input.hasNextLine())
    { buffer=input.nextLine();
      for(i=0;i<buffer.length();i++)
           {if(prev)
               {prev=false;
                html=false;
                }
           else if(buffer.charAt(i)=='<')
                 html=true;
            else if(buffer.charAt(i)=='>')
                  prev=true;
            if(!html)
                 System.out.print(buffer.charAt(i));
            }
        System.out.println();
        prev=false;
     html=false;

        }  

    }




}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote