python challenge challenge 3のjava解


1は、ページを表示するソースコードでもあります
2,乱雑文字の中から左右3文字の大文字で囲まれた小文字を探す
3、httpClientを使う


import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;

public class Challenge3Search {

	public static void main(String[] args) throws HttpException, IOException {
		HttpClient client = new HttpClient(); 
		GetMethod get = new GetMethod("http://www.pythonchallenge.com/pc/def/equality.html");
		client.executeMethod(get);
		String pageInfo = get.getResponseBodyAsString();
		get.releaseConnection();
		System.out.println(getRegularLowLetter(pageInfo));
	}
	
	public static String getRegularLowLetter(String str){
		StringBuilder out = new StringBuilder();
		
		for(int i = 3; i< str.length()-3; i++){
			int count = 0;
			for(int j = 1 ; j < 4; j++){				
				if(Character.isUpperCase(str.charAt(i-j)) && Character.isUpperCase(str.charAt(i+j)) && Character.isLowerCase(str.charAt(i))){
					count++;
				}
				if(count == 3 && Character.isLowerCase(str.charAt(i-4)) && Character.isLowerCase(str.charAt(i+4)))
					out.append(str.charAt(i));
			}		
		}
		return out.toString();
	}
	
}