[go: up one dir, main page]

0% found this document useful (0 votes)
12 views2 pages

SerieFibonacci Java

This Java program defines two methods, one to calculate and print the Fibonacci sequence up to a given number, and another to calculate and return the Fibonacci sequence as a string.

Uploaded by

Rodrigo Barahona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

SerieFibonacci Java

This Java program defines two methods, one to calculate and print the Fibonacci sequence up to a given number, and another to calculate and return the Fibonacci sequence as a string.

Uploaded by

Rodrigo Barahona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package lab2;

public class Lab2 {

public static void main(String[] args) {

fibonacci(5);

System.out.println(fibonacciCadena(7));

public static void fibonacci (int n)

int c=0, a=-1, b=1;

for (int i=1; i<=n; i++){

c=a+b;

a=b;

b=c;

System.out.println(" "+c);

public static String fibonacciCadena (int n)

int c=0, a=-1, b=1;

String cad="";

for (int i=1; i<=n; i++){

c=a+b;

a=b;

b=c;

//System.out.println(" "+c);
cad=cad+" "+c;

return cad;

You might also like