Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dailyprogrammer;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.util.ArrayList;
- import static java.lang.System.out;
- public class Intermediate17 {
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- out.println("Connecting...");
- URL url = new URL("http://www.reddit.com/r/dailyprogrammer/comments/qhe4u/342012_challenge_17_intermediate/");
- BufferedReader in = new BufferedReader(new InputStreamReader(
- url.openStream()));
- String inputLine;
- ArrayList<String> quotes = new ArrayList<String>();
- while ((inputLine = in.readLine()) != null) {
- if (inputLine.length() > 2) {
- int startQuote = inputLine.indexOf(""");
- int endQuote = inputLine.indexOf(""", startQuote+1);
- if (startQuote != -1) {
- quotes.add(inputLine.substring(startQuote+6, endQuote));
- }
- }
- }
- out.println("Quotes on webpage enclosed in \""\" tag as per example:");
- out.println("Webpage: "+url);
- out.println("Number of quotes = " + quotes.size());
- for (int i = 0; i < quotes.size(); i++) {
- out.printf("%d: ", i+1);
- out.println(quotes.get(i));
- }
- }
- }
Add Comment
Please, Sign In to add comment