Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  Fibonacci
Language: JAVA
Code:

import java.util.Scanner;


public class Fibonacci
{
               
                      
          public Fibonacci()
          {
                    try
                {  
                         System.out.println("Digite a quantidade de Numeros que voce quer que a sequencia tenha:");
                         Scanner teclado = new Scanner(System.in);
                        int Qtde_de_Numeros = Integer.parseInt(teclado.next());
                        Imprime_Fibonacci(Qtde_de_Numeros);
                }
                catch(Exception e)
                { }  
          }      
          public void Imprime_Fibonacci(int Numero)
          {
               int x = 0;
               int y = 1;
               while(Numero >0)
               {
                         System.out.println(y+"; ");
                         x = x + y;
                         System.out.println(x+"; ");
                         y = y + x;
                         Numero = Numero - 2; //A cada passagem ele imprime 2 numeros por isto aqui é -2 
               }               
               
          }           
         public static void main(String args [])
         {
                   new Fibonacci();
                                      
         }
    
    
}
Comments: