标题:复数幂

匿名 (未验证) 提交于 2019-12-03 00:15:02
public class demo5 {      public static void main(String[] args) {         try {             PrintStream ps = System.out;             PrintStream prs = new PrintStream(new File("C:\\Users\\Laptop\\Desktop\\ans\\ans.txt"));             System.setOut(prs);             work(123456);             System.setOut(ps);         } catch (FileNotFoundException e) {             e.printStackTrace();         }     }      private static void work(int n) {         BigInteger x = BigInteger.valueOf(2);         BigInteger y = BigInteger.valueOf(3);          for (int i = 1; i < n; i++) {             BigInteger tmp1 = x.multiply(BigInteger.valueOf(2)).subtract(y.multiply(BigInteger.valueOf(3)));             BigInteger tmp2 = x.multiply(BigInteger.valueOf(3)).add(y.multiply(BigInteger.valueOf(2)));              x = tmp1;             y = tmp2;         }         System.out.println(x + "" + y + "i");// 输出结果     } }

划重点,这个输出到文件代码要记。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!