-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacciTester.java
More file actions
35 lines (33 loc) · 1.01 KB
/
FibonacciTester.java
File metadata and controls
35 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
public class FibonacciTester
{
//Simply asks user to input the fibonacci series
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
//Initialization
int faultCount = 0;
int currentNum = 1;
int previousNum = 1;
inputLoop:
while (scanner.hasNext())
{
while (!scanner.hasNextInt()) //Skipping any token which is not a number
scanner.next();
int nextNum = currentNum + previousNum;
while (scanner.nextInt() != nextNum)
{
faultCount++;
if (faultCount > 3)
{
System.out.println("You lose!");
break inputLoop;
}
System.out.println("Please try again!");
}
faultCount = 0;
previousNum = currentNum;
currentNum = nextNum;
}
}
}