zoukankan      html  css  js  c++  java
  • 第二次测试补做

    1.P29

    Example2_5

    2.P45

    Example3_7

    3.递归循环

    text

    代码

    import java.util.Scanner;
    public class text2 {
        public static void main(String[] args) {
            long sum = 0;
            Scanner scanner = new Scanner(System.in);
            System.out.println("Please input n:");
            int n = scanner.nextInt();
            if (n < 0) {
                System.out.println("Please input a number ");
            }
            for (int i = 1; i <= n; i++) {
                sum += fact(i);
            }
            if(n>0)
                System.out.println("1!+...+"+n+"!="+sum);
            else
                System.out.println("0!="+1);
    
        }
    
        public static long fact(int t) {
            if (t == 0)
                return 1;
            else
                return t * fact(t - 1);
        }
    }
    

    4.jdb
    可能是因为电脑的问题,我在使用git bush对上述代码进行调试总是失败,我会在安装好虚拟机之后补上本次内容。

  • 相关阅读:
    导论
    Array
    Singleton
    Bridge
    Mediator
    interpreter
    Visitor
    Flyweight
    Command
    Chain Of Responsibility
  • 原文地址:https://www.cnblogs.com/violence/p/8653588.html
Copyright © 2011-2022 走看看