0% found this document useful (0 votes)
26 views1 page

Fibonacci

The document contains a Java program that generates a Fibonacci series using three different loop constructs: for, while, and do-while. Each loop prints the first ten numbers of the Fibonacci sequence, with appropriate formatting for the output. The program initializes variables for the Fibonacci calculation and iterates through the series, printing the results to the console.

Uploaded by

Majo Molina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Fibonacci

The document contains a Java program that generates a Fibonacci series using three different loop constructs: for, while, and do-while. Each loop prints the first ten numbers of the Fibonacci sequence, with appropriate formatting for the output. The program initializes variables for the Fibonacci calculation and iterates through the series, printing the results to the console.

Uploaded by

Majo Molina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

public class ejercicio{

public static void main(String args[]){

int i = 0, a = 3, b = 5, c = 0;

System.out.println("Serie con for: ");


for(i = 0; i < 10; i++){
if(i < 9){
System.out.print(a + ",");
c = a + b;
a = b;
b = c;
} else {
System.out.print(a);
}
}
System.out.println("");
i = 0;
b = 1;
a = 0;
c = 0;

System.out.println("Serie con while: ");


while(i < 10){
if(i < 9){
System.out.print(a + ",");
c = a + b;
a = b;
b = c;
} else {
System.out.print(a);
}
i++;
}
System.out.println("");
i = 0;
b = 1;
a = 0;
c = 0;

System.out.println("Serie con do-while: ");


do{
if(i < 9){
System.out.print(a + ",");
c = a + b;
a = b;
b = c;
} else {
System.out.print(a);
}
i++;
}while(i < 10);

}
}

You might also like