Advertisement
MEI-BoatRider

fib seq. in java

Feb 26th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.        
  4.         //Main variables
  5.         long variNull = 0l;
  6.         long variEins = 1l;
  7.         long variZwei = 0l;
  8.         int i = 0;
  9.         int x = 0;
  10.         //goal, procid fib seq.
  11. /*  
  12. 0, 1, 2
  13. 3, 5, 8
  14. 13, 21, 34
  15. */
  16.         do {
  17.             //math
  18.             i++;
  19.             variZwei = variNull + variEins;
  20.            
  21.             //prints the seq.
  22.             System.out.println(variZwei);
  23.            
  24.             //changes variables
  25.         switch(x)
  26.                 {
  27.                     case 0:
  28.                     x++;
  29.                     variNull = variZwei;
  30.                 break;
  31.            
  32.                     case 1:
  33.                     x--;
  34.                     variEins = variZwei;
  35.                 break;
  36.                
  37.    }
  38.   } while (i < 45);
  39.  }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement