1. JAVA WEEK1(B)
/*
Week 1:
b) The Fibonacci sequence is defined by the following rule: The fist two values in
the sequence are 1 and 1. Every subsequent value is the sum of the two values
preceding it. Write a Java program that uses both recursive and non recursive
functions to print the nth value in the Fibonacci sequence. */
import javax.swing.*;
public class Fibo
{
public static void main(String args[])
{
String n1;
int f1=1,f2=1,n,i,f3;
n1=JOptionPane.showInputDialog("enter n value");
n=Integer.parseInt(n1);
JOptionPane.showMessageDialog(null,"series"+f1+f2);
for(i=1;i<=n;i++)
{
f3=f1+f2;
JOptionPane.showMessageDialog(null,f3);
f1=f2;
f2=f3;
}
}
}
Page 1