Created
June 1, 2015 23:12
-
-
Save defHLT/8eccbefd5eee5247d984 to your computer and use it in GitHub Desktop.
Fib generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Iterator; | |
class HelloWorldApp { | |
public static void main(String[] args) { | |
Iterable<Integer> fibo = new Iterable<Integer>() { | |
@Override | |
public Iterator<Integer> iterator() { | |
return new Iterator<Integer>() { | |
int a = 0; | |
int b = 1; | |
int total; | |
@Override | |
public boolean hasNext() { | |
return true; | |
} | |
@Override | |
public Integer next() { | |
int old_a = a; | |
a = b; | |
b = old_a + b; | |
return old_a; | |
} | |
@Override | |
public void remove() { | |
throw new UnsupportedOperationException(); | |
} | |
}; | |
} | |
}; | |
Iterator<Integer> it = fibo.iterator(); | |
int n = 0; | |
while (n++ < 25) { | |
System.out.print(it.next() + " "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment