(Coursera) Data Structures and Algorithms Specialization/Nagendra/Algorithmic Toolbox/week2_algorithmic_warmup/2_last_digit_of_fibonacci_number/FibonacciLastDigit.java
<filename>(Coursera) Data Structures and Algorithms Specialization/Nagendra/Algorithmic Toolbox/week2_algorithmic_warmup/2_last_digit_of_fibonacci_number/FibonacciLastDigit.javaimport java.util.*;

public class FibonacciLastDigit {
    private static int getFibonacciLastDigitNaive(int n) {
        if (n <= 1)
            return n;

        int previous = 0;
        int current  = 1;

        for (int i = 0; i < n - 1; ++i) {
            int tmp_previous = previous;
            previous = current;
            current = tmp_previous + current;
        }

        return current % 10;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int c = getFibonacciLastDigitNaive(n);
        System.out.println(c);
    }
}

