日期:2014-05-20  浏览次数:20633 次

关于java.lang包的题目!
1、有一段网页代码为:
<html>
<head> 欢迎 </head>
<body>
<a   href= 'http://www.hn.com '> 湖南 </a>
<a   href= 'http://www.hb.com '> 湖北 </a>
<a   href= 'http://www.gd.com '> 广东 </a>
<a   href= 'http://www.gx.com '> 广西 </a>
<a   href= 'http://www.bj.com '> 北京 </a>
</body>
</html>
请编写一个程序用来分析以上这段代码,要求输出结果为:
湖南:http://www.hn.com
湖北:http://www.hb.com
广东:http://www.gd.com
广西:http://www.gx.com
北京:http://www.bj.com


2、有一个字符串是:select   *   from   myTable   where   id=?   and   pwd=?,
      一个字符串数组是String[]   pras=new   String[]{ "0001 ", "123456 "};
      请编写一个程序,使用以上字符串,和字符数组,生成一个完整的SQL语句,如:
select   *   from   myTable   where   id= '0001 '   and   pwd= '123456 '
并输出结果。

3、编写一个程序,要求用户输入两个数,如5.6239和10.36,使用包装类将其转换成
      double数据类型,要求以百分数输出,并要求小数部分最少保存3位有效数据。如:
                  500.624%
                  1000.360%
        输出结果。


谁能解答啊!

------解决方案--------------------
java.util.regex.Pattern p=java.util.regex.Pattern.compile( " <a href=.*> .* </a> ");
java.util.regex.Pattern p1=java.util.regex.Pattern.compile( "> .* < ");
java.util.regex.Pattern p2=java.util.regex.Pattern.compile( " '.* ' ");
java.io.File file = new java.io.File( "d://index.html ");
java.io.FileReader reader=new java.io.FileReader(file);
java.io.BufferedReader in=new java.io.BufferedReader(reader);
String s;
while((s=in.readLine())!=null)
{
java.util.regex.Matcher m=p.matcher(s);
if(m.find())
{
java.util.regex.Matcher m1=p1.matcher(m.group());
java.util.regex.Matcher m2=p2.matcher(m.group());
m1.find();
m2.find();
System.out.println(m1.group()+ ": "+m2.group());


}
}
in.close();


这是第一个的答案。

第二个就是字符串替换的问题。

第三个自己看看数据的格式化就能写了