zoukankan      html  css  js  c++  java
  • 标题:复数幂

    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");// 输出结果
        }
    }

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

  • 相关阅读:
    GDB 用法
    C编程规范
    PHP面向对象
    cron定时任务
    Apatche配置基础
    正则表达式笔记
    PHP在windows下命令行方式
    面试题
    struts与ajax的关系
    ORACLE DUAL表详解
  • 原文地址:https://www.cnblogs.com/hardhp74520/p/11739919.html
Copyright © 2011-2022 走看看