Advertisement
scottashipp

Obfuscated Fibonacci

Jun 25th, 2013
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. public class Fibonacci2 {
  2.  
  3.         public static void main(String[] args) {
  4.             System.out.println("Please enter the number of Fibonacci numbers to display: ");
  5.             Scanner s = new Scanner(System.in);
  6.             Integer n = s.nextInt();
  7.            
  8.             int a = 0; //a = x
  9.             int b = 1;  // b = i
  10.             System.out.print(a + ", ");
  11.             System.out.print(b);
  12.             for(int i=1; i < n-1; i++) {
  13.                 System.out.print(", " + b);
  14.                 a = b - a;
  15.                 b = b + a;
  16.             }
  17.         }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement