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%
    输出结果。
谁能解答啊!

解决方案 »

  1.   

    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();
    这是第一个的答案。第二个就是字符串替换的问题。第三个自己看看数据的格式化就能写了
      

  2.   

    谢谢,如果第一题只学到 java.lang包  改怎么解决呢。
      

  3.   

    第一个题目要是非用lang包解决的话我只能想到跟第二题一样的用String类里的截取字符串!
    第三题用lang包的解决方法如下:
    public class swich(){
        public static void main(String[] args){
            Bufferdreader b1 = new Bufferdreader(new InputStreamreader(System.in));
            Bufferdreader b2 = new Bufferdreader(new InputStreamreader(System.in));
            double d1 = Double.par....(b.readline);
            double d2 = Double.par....(b.readline);
            System.out.print(d1*100+"%"+d2*100+"%");
        }
    }
      

  4.   

    小数点后三位的问题忘了帮你解决! 头两句不变!一下语句的改动如下:
            String s1 = b1.readline;
            String s2 = b2.readline;
            if(s1.index('.')==-1){
                System.out.print(s1+".000");
            }
            else{
                double d1 = Double.par....(s1.substring(0,s1.index('.')+4))
                System.out.print(d1);
            }
    d2的写法同上!至于判断输入数据类型和异常就自己加吧!我cry异常都是用工具直接套!手动不习惯!所以在这里就留给你自己了!
      

  5.   

    第3题还是有问题.555
    第一题如果我写成这样。怎样完成呢。
    import java.lang.*;public class Lei
    {
    public static void main(String[] args) 
    {
    String str = "<html>\n\t<head>欢迎</head>\n\t<body>"
    +"\n\t\t<a href='http://www.hn.com'>湖南</a>"
    +"\n\t\t<a href='http://www.hb.com'>湖北</a>"
    +"\n\t\t<a href='http://www.gd.com'>广东</a>"
    +"\n\t\t<a href='http://www.gx.com'>广西</a>"
    +"\n\t\t<a href='http://www.bj.com'>北京</a>\n\t</body>\n</html>";
    System.out.println (str);.....