Q:

Printing a particular value from an array

How can I print the value of a Fibonacci function for any particular index, say n, where n is the provided argument value?
1 import java.util.Arrays;
2 
3 public class Fibonacci {
4
5 public static void main(String[] args) {
6   int n = Integer.parseInt(args[0]);
7   if(n<3){
8       return;
9   }else{
10      int[] f = new int[n];
11      f[0] = 1;
12      f[1] = 1;
13      int i= 0;
14      for(i=2; i<f.length; i++){
15          f[i]= f[i-1]+ f[i-2];
16      }
17      System.out.println(f[i]);
18  }
19  
20 }
21
22 }

A:

Your code is basically fine, but I tweaked a few things in my response:
public static void main(String[] args) {
    int n = Integer.parseInt(args[0]);
    if (n < 0) {
        System.out.println("Cannot computer Fib() of a negative number.");
        return(0);
    } else if (n < 3) {
       System.out.println("Fib[" + n + "] = 1");
    } else {
        int[] f = new int[n];
        f[0] = 1;
        f[1] = 1;
        for(int i=2; i < f.length; ++i) {
            f[i] = f[i-1]+ f[i-2];
        }
        System.out.println("Fib[" + n + "] = " + f[n - 1]);
    }
}

