can not add the 2 numbers
class fibo
{
int a;
int b;
int c;
int x;
boolean flag;
fibo(int x)
{
int a=2;
int b=3;
this.x=x;
System.out.println("the value of a : " + a);
System.out.println("the value of b : " + b);
flag=true;
}
void fibonoci()
{
for(int n=1; n<=x; n++)
{
if(flag==true)
{
c=a+b;
System.out.println(c);
a=c;
c=0;
flag=false;
}
else
{
c=a+b;
System.out.println(c);
b=c;
c=0;
flag=true;
}
}
}
}
class fibonocis
{
public static void main(String args[])
{
fibo fib=new fibo(10);
fib.fibonoci();
}
}
this is the program i have written to get the answer in fibonoci series but i am not abel to get the answer please help out
[898 byte] By [
d_e_e_pa] at [2007-11-26 16:41:06]

Have a look at your Constructor. The basic mistake you made is the reason why there is a convention to name member variables with m_...
You redefined a and b in your Constructor and so the memver variable a and b of your class never got initialized (they are still 0).
But there is another mistake as well. Even if you correct his mistake the resulting series of integers seems not be correct.
> In the privacy of their own homes/business it isn't.
> But in a public forum, it is very much open to me to
> point out that the person is misrepresenting his own
> personal choice as a "convention"
And to do so you choose your own very personal "convention". You spat on g_magoss and his family.
You shouldn't have done that because you're wrong and g_magoss is right. The convention he mentioned exists (and is not his private or IDE specific) and is used to avoid the problem he pointed out.
class fibonocis
{
public static void main(String args[])
{
System.out.println(fib(7));
}
public static int fib(int x)
{
if(x == 1)
{
return 2;
}
else if(x==2)
{
return 3;
}
return (fib(x-1)+fib(x-2));
}
}
here is the code .. it will give you the answer to what ever value you give in your main