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

Program to illustrate the concept of templates.

To create an html file to implement the concept of margin, padding using cascading style sheets.

To configure the IP address for a computer connected to LAN