prefixedfibonacci.java

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

JAVA
57
字号
import org.jdom.Element;import org.jdom.Document;import org.jdom.output.XMLOutputter;import java.math.BigInteger;import java.io.IOException;public class PrefixedFibonacci {  public static void main(String[] args) {    Element root = new Element("math", "mathml",     "http://www.w3.org/1998/Math/MathML");    BigInteger low  = BigInteger.ONE;    BigInteger high = BigInteger.ONE;    for (int i = 1; i <= 5; i++) {      Element mrow = new Element("mrow", "mathml",       "http://www.w3.org/1998/Math/MathML");      Element mi = new Element("mi", "mathml",       "http://www.w3.org/1998/Math/MathML");      mi.setText("f(" + i + ")");      mrow.addContent(mi);      Element mo = new Element("mo", "mathml",       "http://www.w3.org/1998/Math/MathML");      mo.setText("=");      mrow.addContent(mo);      Element mn = new Element("mn", "mathml",       "http://www.w3.org/1998/Math/MathML");      mn.setText(low.toString());      mrow.addContent(mn);      BigInteger temp = high;      high = high.add(low);      low = temp;      root.addContent(mrow);    }    Document doc = new Document(root);    try {      XMLOutputter serializer = new XMLOutputter("  ", true);      serializer.output(doc, System.out);    }    catch (IOException e) {      System.err.println(e);    }  }}

⌨️ 快捷键说明

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