当前位置:网站首页>1106 2019 Sequence (15 points)

1106 2019 Sequence (15 points)

2022-08-11 07:48:00 dumb bit

题目要求:
在这里插入图片描述
代码:

import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
    
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

        String [] array = new String[1000];
        array[0] = "2";
        array[1] = "0";
        array[2] = "1";
        array[3] = "9";
        //加数
        for (int i = 0; i < n-4; i++) {
    
            int sum = Integer.valueOf(array[i]) + Integer.valueOf(array[i+1]) + Integer.valueOf(array[i+2]) + Integer.valueOf(array[i+3]);
            String right = sum % 10 + "";
            array[i + 4] = right;
        }
        //Convert valid bits to array、
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < n; i++) {
    
            stringBuilder.append(array[i]);
        }
        System.out.println(stringBuilder);
    }
}

结果:
在这里插入图片描述

原网站

版权声明
本文为[dumb bit]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110645413300.html