forked from stiers/COPRO2_SampleJavaPrograms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFibonacci_MOD.java
32 lines (21 loc) · 861 Bytes
/
Fibonacci_MOD.java
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
import java.io.*;
public class Fibonacci_MOD {
public static void main( String args[] ) throws IOException {
BufferedReader console = new BufferedReader( new InputStreamReader( System.in ) );
int current, previous1, previous2, counter, nthFibonacci;
System.out.print( "Enter the first fibonacci number: " );
previous1 = Integer.parseInt( console.readLine() );
System.out.print( "Enter the second fibonacci number: " );
previous2 = Integer.parseInt( console.readLine() );
System.out.print( "Enter the desired fibonacci number: " );
nthFibonacci = Integer.parseInt( console.readLine() );
counter = 3;
while( counter <= nthFibonacci ) {
current = previous2 + previous1;
previous1 = previous2;
previous2 = current;
counter ++;
}
System.out.println( "The " + nthFibonacci + "th Fibonacci number is: " + current );
}
}