AlexKondov

Java Multiple Sequences

May 9th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package IntroductionToJava.Exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TribonacciSpiral {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.         int firstNum = input.nextInt();
  10.         int secondNum = input.nextInt();
  11.         int thirdNum = input.nextInt();
  12.         int total = 0;
  13.         int[] trib = new int[1000000];
  14.        
  15.         int firstNumber = input.nextInt();
  16.         int step = input.nextInt();
  17.         int stepNumber = 0;
  18.         int[] spiral = new int[1000000];
  19.        
  20.         for (int j = 0; j < 20; j++) {
  21.             total = firstNum + secondNum + thirdNum;
  22.             firstNum = secondNum;
  23.             secondNum = thirdNum;
  24.             thirdNum = total;
  25.             trib[j] = total;
  26.         }
  27.         for (int i = 0; i < 20; i++) {
  28.             stepNumber = firstNumber + step;
  29.             firstNumber = stepNumber;
  30.             spiral[i] = stepNumber;
  31.         }
  32.        
  33.         for (int i : trib) {
  34.             for (int j : spiral) {
  35.                 if (i == j) {
  36.                     System.out.println(i);
  37.                     return;
  38.                 }
  39.                 else {
  40.                     continue;
  41.                 }
  42.             }
  43.         }
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment