BUILDING JAVA PROGRAMS-TEXT
BUILDING JAVA PROGRAMS-TEXT
5th Edition
ISBN: 2810023481209
Author: REGES
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 6, Problem 13E

Explanation of Solution

Program code:

JavaStripper.java

//import the required packages

import java.io.File;

import java.util.Arrays;

import java.util.Scanner;

//define a class JavaStripper

public class JavaStripper

{

//define the main

public static void main(String[] args) throws Exception

{

//create the object of File class

File fileName = new File("htmlfile.txt");

//create the object of Scanner class to refer the file

Scanner inFile = new Scanner(fileName);

//call the method stripComments()

stripComments(inFile);

    }

//define a method stripComments()

public static void stripComments(Scanner inFile) throws Exception

{

//create a string variable inputstring

String inputstring = "";

//iterate a while loop

while (inFile.hasNextLine())

{

    //read the line to inputstring

inputstring = inputstring + " \n " + inFile.nextLine();

}

//create a character array

char[] inputchar = inputstring.toCharArray();

//create an integer variable

int nCommentBegin = 0;

//create a boolean variable

boolean IsLineCommentOpen = false;

//iterate a for loop

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

{

    //if the condition is true

    if(inputchar[i] == '/' && inputchar[i+1] == '*')

    {

        //set as starting of comment

        nCommentBegin = i;

    }

    //else condition

else if(inputchar[i] == '*' && inputchar[i+1] == '/')

    {

        //remove the comments within /* */

char[] str2Remove = Arrays.copyOfRange(inputchar, nCommentBegin,(i+2));

        //set the value of inputstring

inputstring = inputstring.replace(new String(str2Remove), "");

    }

    //else condition

else if(inputchar[i] == '/' && inputchar[i+1] == '/')

    {

        //set as the beggning of single line comment

        nCommentBegin = i;

        IsLineCommentOpen = true;

    }

    //else if the character is \n

    else if(inputchar[i] == '\n')

    {

        //checks the va

        if(IsLineCommentOpen)

        {

            //set the value of str2Remove

char[] str2Remove = Arrays.copyOfRange(inputchar, nCommentBegin,i);

//call the replace() method

inputstring = inputstring.replace(new String(str2Remove), "");

//set the value of IsLineCommentOpen to false

IsLineCommentOpen = false;

        }

        }

}

//print the inputstring

System...

Blurred answer
Students have asked these similar questions
I cannot program smart home automation rules from my device using a computer or phone, and I would like to know how to properly connect devices such as switches and sensors together ? Cisco Packet Tracer 1. Smart Home Automation:o Connect a temperature sensor and a fan to a home gateway.o Configure the home gateway so that the fan is activated when the temperature exceedsa set threshold (e.g., 30°C).2. WiFi Network Configuration:o Set up a wireless LAN with a unique SSID.o Enable WPA2 encryption to secure the WiFi network.o Implement MAC address filtering to allow only specific clients to connect.3. WLC Configuration:o Deploy at least two wireless access points connected to a Wireless LAN Controller(WLC).o Configure the WLC to manage the APs, broadcast the configured SSID, and applyconsistent security settings across all APs.
using r language for integration theta = integral 0 to infinity (x^4)*e^(-x^2)/2 dx (1) use the density function of standard normal distribution N(0,1) f(x) = 1/sqrt(2pi) * e^(-x^2)/2 -infinity <x<infinity as importance function and obtain an estimate theta 1 for theta set m=100 for the estimate whatt is the estimate theta 1? (2)use the density function of gamma (r=5 λ=1/2)distribution f(x)=λ^r/Γ(r) x^(r-1)e^(-λx) x>=0 as importance function and obtain an estimate theta 2 for theta set m=1000 fir the estimate what is the estimate theta2? (3) use simulation (repeat 1000 times) to estimate the variance of the estimates theta1 and theta 2 which one has smaller variance?
using r language A continuous random variable X has density function f(x)=1/56(3x^2+4x^3+5x^4).0<=x<=2 (1) secify the density g of the random variable Y you find for the acceptance rejection method. (2) what is the value of c you choose to use for the acceptance rejection method (3) use the acceptance rejection method to generate a random sample of size 1000 from the distribution of X .graph the density histogram of the sample and compare it with the density function f(x)

Chapter 6 Solutions

BUILDING JAVA PROGRAMS-TEXT

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY