Fibonacci1.java_



//La sucesión de Fibonacci
//1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144....
import java.io.*;

class Fibonacci
{
	public static void main(String R[])
	{
		FIBONACCI fibonacci = new FIBONACCI();
		fibonacci.Inicia();
	}
}

class FIBONACCI
{
	void Inicia()
	{
		int N = 0, DIM = 100;
		int Vector[] = new int[DIM];
		Lee PideDato = new Lee();
		N = Integer.parseInt(PideDato.LeeDato("\nHasta que numero de la sucesion?: "));
		Vector = Genera(N);
		Imprime(Vector, N);
		System.out.println("\nFin de la sucesion...");
	}

	void Imprime(int V[], int N)
		{ for (int x = 0; x < N; x++) System.out.println(", " + V[x]); }

	int []Genera(int N)
	{
		int V[] = new int[N];

		for (int x = 0; x < N; x++)
			if (x == 1 || x == 0)  V[x] = 1; else V[x]= V[x-1] + V[x-2];
		return V;
	}
}

class Lee
{
	String LeeDato(String MENSAJE)
	{
		String sdato = "";
		try
		{
			//Definir un flujo de caracteres de entrada: flujoE
			InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader flujoE = new BufferedReader(isr);

			//Leer.La entrada finaliza al pulsar la tecla Entrar
			System.out.println(MENSAJE + " :> ");
			sdato = flujoE.readLine();
		}
		catch (IOException e) { System.err.println("Error: " + e.getMessage()); }
		return sdato; // devolver el dato tecleado
	}
}