python challenge challenge3 之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();
}
}
页:
[1]