Fibonacci Series in Java - Java programming language tutorial on how to get series of fiboncacci in java.


Fibonacci Series in Java
import java.io.*;
class fibo{
public static void main(String args[])throws IOException{
Integer a,i;
Integer b,c,d,e,f,j;
String s1,s2;
Integer temp;
Integer add,mul,sub,div;
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
System.out.print("Enter the value of a = ");
s1=br.readLine();
System.out.print("Enter the value of b = " );
s2=br.readLine();
a=Integer.valueOf(s1);
b=Integer.valueOf(s2);
c=a+b;
d=a*b;
e=a-b;
f=a/b;
System.out.println(" addition of two number= " +c);
System.out.println(" subtraction of two number= " +e);
System.out.println(" multiplication of two number= "+d);
System.out.println(" division of two number= "+f);
add=c;
mul=d;
temp=add;
add=mul;
mul=temp;
sub=e;
div=f;
temp=sub;
sub=div;
div=temp;
System.out.println("\n\nAfter swapping value");
System.out.println(" After swapping the addition is= "+add);
System.out.println(" After swapping the multiplication is= "+mul);
System.out.println(" After swapping the sub is= "+sub);
System.out.println(" After swapping the division is= "+div);
System.out.println("\n\nSwaping without third variable");
add=add+mul;
mul=add-mul;
add=add-mul;
div=div+sub;
sub=div-sub;
div=div-sub;
System.out.println(" After swapping the addition is= "+add);
System.out.println(" After swapping the multiplication is= "+mul);
System.out.println(" After swapping the sub is="+sub);
System.out.println(" After swapping the division is="+div);
Integer s=0;
if(a<b){
for(i=a;i<=b;i++)
{
s=s+i;
}
System.out.println("The series summation is= "+s);
}
else{
System.out.println("\n\nWarning :::::::");
System.out.println("The series summation is not possible.");
}
if ( s % 2 == 0 )
{
System.out.println("The series summation number is even.");
}
else{
System.out.println("The series summation number is odd.");
}
Integer h=1;
for(i=a;i<=b;i++)
{
h=h*i;
}
System.out.println("The factorial number of b to a is :"+h);
Integer n=9;
System.out.print("Fibonacci Series is =");
for(i=1;i<=9;i++){
System.out.print(" "+a);
c=a+b;
a=b;
b=c;
}
}
}
0 Comments