Fibonacci Series in java

CODE :

a)
WHILE LOOP

public class P_04_fibb_while_loop {
public static void main(String[] args) {
int a=1,temp=0,b=0;
System.out.println(a);
while (a<10) {
temp=a+b;
b=a;
a=temp;
System.out.println(temp);
temp++;
}
}

}

b)
DO WHILE LOOP

public class P_04_do_fibb_while_loop {
public static void main(String[] args) {
int a=1,temp=0,b=0;
System.out.println(a);
do{
temp=a+b;
b=a;
a=temp;
System.out.println(temp);
temp++;
}while (a<10);
}

}

c)
FOR LOOP

public class P_04_fibb_for_loop {
public static void main(String[] args) {
int a=1,temp=0,b=0;
System.out.println(a);
for(;a<10;temp++) {
temp=a+b;
b=a;
a=temp;
System.out.println(temp);
}
}

}


Output :



Comments

Popular posts from this blog

To implement the various components of HTML5 Canvas

Program to illustrate the concept of templates.

Program to illustrate the order of execution of constructors and destructors in inheritance.