Create a Java Program that takes a URL and calculates the nu
Create a Java Program that takes a URL and calculates the number of lines and characters on the page.
Program should include:
URL selectedURL = new URL (address)
BufferedReader bf = new BufferedReader(
(new InputStreamReader(selectedURL.openStream())));
Solution
URLRead.java
import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.Scanner;
 import java.net.URL;
public class URLRead {
  
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        System.out.println(\"Enter an address: \");
        String address = scan.next();
        URL selectedURL = new URL (address);
        int numOfLines = 0, charCount = 0;
        BufferedReader bf = new BufferedReader(
        (new InputStreamReader(selectedURL.openStream())));
        String sCurrentLine;
        while ((sCurrentLine = bf.readLine()) != null) {
            numOfLines++;
            charCount = charCount + sCurrentLine.length();
        }
        System.out.println(\"Number of lines: \"+numOfLines);
        System.out.println(\"Number of characters: \"+charCount);
    }
}
Output:
Enter an address:
 http://www.javatpoint.com/java-tutorial
 Number of lines: 313
 Number of characters: 32907

