I have coded fibonacci series using java language , and finished with this solution, how it appears and is that a better solution ?
static int loopFibonacci(int num) {
if(num <1) {
throw new IllegalArgumentException("this number is not valid for fibonacci series");
}
int sum = 1;
int prev = 0;
for (int i=1;i<num;i++) {
sum+=prev;
prev = sum-prev;
// System.out.println("sum="+sum+" , prev = "+prev);
}
return sum;
}
}
`