fibonaccifile.java
来自「随书的代码」· Java 代码 · 共 46 行
JAVA
46 行
import java.math.BigInteger;import java.io.*;public class FibonacciFile { public static void main(String[] args) { BigInteger low = BigInteger.ONE; BigInteger high = BigInteger.ONE; try { OutputStream fout= new FileOutputStream("fibonacci.xml"); OutputStream bout= new BufferedOutputStream(fout); OutputStreamWriter out = new OutputStreamWriter(bout, "8859_1"); out.write("<?xml version=\"1.0\" "); out.write("encoding=\"ISO-8859-1\"?>\r\n"); out.write("<Fibonacci_Numbers>\r\n"); for (int i = 1; i <= 10; i++) { out.write(" <fibonacci index=\"" + i + "\">"); out.write(low.toString()); out.write("</fibonacci>\r\n"); BigInteger temp = high; high = high.add(low); low = temp; } out.write("</Fibonacci_Numbers>\r\n"); out.flush(); // Don't forget to flush! out.close(); } catch (UnsupportedEncodingException e) { System.out.println( "This VM does not support the Latin-1 character set." ); } catch (IOException e) { System.out.println(e.getMessage()); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?