We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents a0a0d34 + acfbaad commit 2dbd83cCopy full SHA for 2dbd83c
1 file changed
Last Digit of FIbonnaci.java
@@ -0,0 +1,28 @@
1
+import java.util.*;
2
+
3
+public class FibonacciLastDigit {
4
5
+ private static int getFibonacciLastDigitNaive(int n) {
6
+ if (n <= 1)
7
+ return n;
8
9
+ int previous = 0;
10
+ int current = 1;
11
12
+ for (int i = 0; i < n - 1; ++i) {
13
+ int tmp_previous = previous;
14
+ previous = current;
15
+ current = (tmp_previous + current)%10;
16
+ }
17
18
+ return current;
19
20
21
+ public static void main(String[] args) {
22
+ Scanner scanner = new Scanner(System.in);
23
+ int n = scanner.nextInt();
24
+ int c = getFibonacciLastDigitNaive(n);
25
+ System.out.println(c);
26
27
28
+}
0 commit comments