fibonaccijdom.java

来自「随书的代码」· Java 代码 · 共 41 行

JAVA
41
字号
import org.jdom.*;import org.jdom.output.XMLOutputter;import java.math.BigInteger;import java.io.IOException;public class FibonacciJDOM {  public static void main(String[] args) {    Element root = new Element("Fibonacci_Numbers");    BigInteger low  = BigInteger.ONE;    BigInteger high = BigInteger.ONE;    for (int i = 1; i <= 5; i++) {      Element fibonacci = new Element("fibonacci");      fibonacci.setAttribute("index", String.valueOf(i));      fibonacci.setText(low.toString());      root.addContent(fibonacci);      BigInteger temp = high;      high = high.add(low);      low = temp;    }    Document doc = new Document(root);    // serialize it onto System.out    try {      XMLOutputter serializer = new XMLOutputter();      serializer.output(doc, System.out);    }    catch (IOException e) {      System.err.println(e);    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?