Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.Scanner;
- /**
- * User: Adam
- * Date: 9/7/12
- * Time: 3:06 PM
- */
- public class StockQuote {
- public static void main(String[] args) throws IOException {
- echo("Enter a stock to get the price for:");
- Scanner kb = new Scanner(System.in);
- String tick = kb.next();
- final URL url = new URL("http://www.google.com/ig/api?stock=" + tick);
- echo("trying to get the stock price for " + tick + " using " + url);
- final URLConnection connection = url.openConnection();
- connection.setReadTimeout(5000);
- connection.setConnectTimeout(5000);
- final InputStream input = connection.getInputStream();
- final Scanner reader = new Scanner(input);
- while (reader.hasNextLine()) {
- echo("the price is somewhere below");
- echo(reader.nextLine());
- }
- }
- private static void echo(Object o) {
- System.out.println(o);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement