Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MethodsMoreExercise;
- import java.util.Scanner;
- public class O4TribonacciSequence {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int number = Integer.parseInt(scanner.nextLine());
- printTribonacciLine(number);
- }
- private static void printTribonacciLine(int number) {
- int[] newArray = new int[number];
- for (int i = 0; i < number; i++) {
- int sum = 0;
- if (i == 0 || i == 1) {
- sum = 1;
- } else if (i == 2) {
- sum = 2;
- } else {
- sum = newArray[i - 1] + newArray[i - 2] + newArray[i - 3];
- }
- newArray[i] = sum;
- System.out.print(sum + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment