Here are some things you might find useful
- [[Section B Toolkit]]
- [[Validating Numbers Exceptions]]
# Traffic Lights
```java
public class Main {
public static void main(String[] args) throws InterruptedException {
int count = -1;
String[] lights = { "red", "red amber", "green", "amber" };
while (true) {
if (++count > 3)
count = 0;
System.out.println(lights[count]);
Thread.sleep(1000);
}
}
}
```
# Big Integer Fibonacci
Here's a simple program to generate the Fibonacci series.
```java
int x = 0;
int y = 1;
for (int i = 1; i < 100; i++) {
int temp = y;
y = y + x;
x = temp;
System.out.println(y);
}
```
Here are the last few numbers generated:
```
-1507123775
708252800
-798870975
-90618175
-889489150
-980107325
```
What's happening here?
The problem is the int data type only has a range from -2147483648 to 2147483647.
Fortunately Java has the BigInteger type which can store numbers as large as your computer has the capacity for.
```java
BigInteger a = BigInteger.valueOf(0);
BigInteger b = BigInteger.valueOf(1);
for (int i = 1; i < 100; i++) {
BigInteger temp = b;
b = b.add(a);
a = temp;
System.out.println(b);
}
```
Here are the last few numbers now...
```
51680708854858323072
83621143489848422977
135301852344706746049
218922995834555169026
354224848179261915075
```