import java.io.*; import java.net.*; public class stock { public static void main(String a[]) throws Exception { if (a.length!=1) { System.out.println("usage: java Stock "); System.exit(0); } String yahoo = "finance.yahoo.com"; final int httpd = 80; Socket sock = new Socket(yahoo, httpd); PrintStream out = new PrintStream( sock.getOutputStream() ); String cmd = "GET /q?" +"s=" +a[0] +"\n"; out.print(cmd); out.flush(); BufferedReader in =new BufferedReader( new InputStreamReader( sock.getInputStream() ) ); String s=null; int i, j; // pick out the stock price from the pile of HTML // it’s in big bold, get the number following "" while ( (s=in.readLine()) != null) { if ((i=s.indexOf("")) < 0) continue; j = s.indexOf(""); s=s.substring(i+8,j); System.out.println(a[0] +" is at "+s); break; } } }