my dog learned polymorphism*
The moose likes Java in General and the fly likes Fybunic series Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Fybunic series " Watch "Fybunic series " New topic
Author

Fybunic series

Ikram Soomro
Ranch Hand

Joined: Oct 20, 2001
Posts: 42
Hello Friends,
I want to print series like
0 1 1 23581321
previous two digits makes the sum next no.
this is called Fybunic series in Mathematics.
We have to use only one SOP statement in whole program and declare 4 variables only.
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
Hello!
This seems like a school assignment...
But I believe this code does what you want. You might need to clean it up a bit, though.
<code>
public final class Test3 {
private static synchronized void main (String[] string) {
int i, j, k, l, m, n, o, p, q, r;
inner:
for(i = 0, j = 0, System.out.println("NUMBERS: "), k = 0, o = 12, l = 0, p = 0, q = 0, n = 0, m = 0, r = 0;
i < 15;
System.out.println(), i++, j += 2) {
{
l = k + m;
}
while (true) {
m = l;
q++;
j = r;
break;
}
n = j + n;
System.out.print(l);
{
p = p + o-- - o;
{
if(o == 11) {
l++;
n++;
k++;
}

else {
k = m + p - k - q;
continue inner;
}
}
}
}
}
}
</code>
//Kaspar
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hi Ikram -
JUst FYI, the series you're referring to is spelled Fibonacci, after the Italian mathematician who made it popular.
And I agree with Kaspar; you really should do your own homework.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5019
    
    8

Now, now, Kaspar, be nice to the greenhorn...
Ikram, Kaspar is just busting your chops, so don't even try to clean up his code.
Most of us feel that it would be doing you (and your instructor) a disservice if we provide you with the solution.
Try iterating by hand first. Then find a pattern. When you find a pattern, automate the iterations with a loop. If you want to do something fancy, you might even try recursion.
Good Luck!

------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform


Junilu - [How to Ask Questions] [How to Answer Questions]
 
 
subject: Fybunic series