1. public class naloga_1 {
  2. public static void main(String[] args) {
  3. int n = 0;
  4. try {
  5. String niz = javax.swing.JOptionPane.showInputDialog("Koliko števil Fibonaccijevega želiš zaporedja sešteti?");
  6. n = Integer.valueOf(niz).intValue();
  7. } catch(Exception e) {
  8. System.exit(0);
  9. }
  10.  
  11. int[] stevila = new int[n];
  12.  
  13. for(int i = 0; i < n; i++) {
  14. if(i <= 1) {
  15. stevila[i] = 1;
  16. } else {
  17. stevila[i] = stevila[i - 2] + stevila[i - 1];
  18. }
  19. }
  20.  
  21. int vsota = 0;
  22.  
  23. for(int i = 0; i < n; i++) {
  24. vsota += stevila[i];
  25. }
  26.  
  27. System.out.println("Sestevek " + n + " stevil Fibonacijevega zaporedja je: " + vsota);
  28. System.exit(0);
  29. }
  30. }