Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Aluno: Pedro Paulo Freire Oliveira */
- package lab04;
- public class Fibonacci {
- int termoatual = 0;
- int termoanterior = 1;
- double termo, termoant;
- public Fibonacci(){
- this.termoatual = 0;
- this.termoanterior = 1;
- }
- public int proximo(){
- int temp = 0;
- temp = this.termoanterior;
- this.termoanterior = this.termoatual;
- this.termoatual += temp;
- return this.termoatual;
- }
- public int termo(int n){
- this.termoatual = 0;
- this.termoanterior = 1;
- if (n <= 0) return 1;
- for (int i =0; i < n; i++)
- this.termoatual = proximo();
- return this.termoatual;
- }
- public java.lang.String geraTermos(int n){
- String termos = "[";
- this.termoatual = 0;
- this.termoanterior = 1;
- for (int i =0; i < n; i++){
- termos += proximo();
- if (i < n - 1) termos += ", ";
- }
- termos += "]";
- return termos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement