实现如何功能,如何有下一层,下一层的空格要加上一层的空格数。该如何实现。
如::
第一层
    第二层
        第三层
            第四层
                第五层

解决方案 »

  1.   

    public class OutLence {
    public static int OutputChr(int nowLine, int numLine, String Content) { //i为该行前面的空格数,
    StringBuffer s = new StringBuffer();
    if (nowLine > 2){
    numLine += OutputChr(nowLine - 1, numLine, Content);
    }
    for (int i = 0; i < numLine; i++) {
    s.append(" ");
    }
    s.append(Content);
    System.out.println(s.toString());
    return numLine;
    } public static void main(String[] args) {
    OutputChr(6,6,"内容测试");
    }
    }
      

  2.   

    抱歉,没有彻底理解你的意思,你的问题类似于树,合理的数据库结构可以使其非常容易现实:
    我设定celllenth 为6
    id   treeid                   name
    1    000001                   第一层
    2    000001000001             第1节
    3    000001000001000001       第1-1节
    4    000001000002             第2节
    5    000001000002000001       第2-1节
    6    000001000002000001000001 第2-2-1节
    ...分析treeid的数据很容易就可以实现你说的那种输出。
      

  3.   

    谢谢楼上的。
    不过我现在的问题不是数据库交互。
    是用jdom解析XML,然后用如上的方式显示出来。
    找不到你说的那种层次结构。
    比较说一本书的目录,里面有章节,章节里有小节,小节又细分......不知该如何操作。
      

  4.   

    public  void startElement(String uri,String localName,String qname,Attributes attr)
        {
         n++;
    ....
        }    public void endElement(String uri,String localName,String qname)
        {
         n--;
    ....
        }一个n可代表一个\t等。