Java Week1(B) Notepad

455 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
455
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java Week1(B) Notepad

  1. 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

×