0
how can we write a fibunacci sequance less than 1000 in java?
9 Respuestas
+ 4
by first learning how to code and then writing the code to output all fibonacci lower than 1000
+ 2
if you are asking what the code should look like I’d say: please upload what you have tried thusfar so we can help you out with the code.
#notdoingyourhomeworkforyou
+ 1
No Problem!
+ 1
There are several ways to write fibonacci: iteratively, recursively, dynami programming. Which one are you referring to? anyways it is a good way to learn the differernt types f algorithms so learn em all.
0
Fibonacci sequence goes in a way, when the sum of pervious two numbers becomes a new number, first numbers of Fibo are 0 and 1, so the sequance goes as 0, 1, 1, 2, 3, 5, 8... All you have to do is make a method, which would sum up previous numbers and add use them as a new number in the sequence.... how about a LOOP? ;)
0
public class fibunacci {
public static void main(String[] args) {
static long fib(int n)
if (n<=1){
return n;
else
return fib (n-1)+(n_2);
}
System.out.println("");
i dont know how to add lower 1000 with a loop.
}
0
Have you learned about While and For loops? Both would allow you to achieve the requirements, although I personally would go with WHILE, so it would start with a condition, E.G. while (maxNumber **** 1000) - replace **** with what would meet the criteria of your requirement and then proceed to create the loop. Right here in Solo, we have a good section about htose loops in Java.
0
tnx bro
- 1
🤨🤨🤨