fibonaccio y factorial

Download Fibonaccio y factorial

If you can't read please download the document

Upload: christian-beltran

Post on 08-Dec-2015

212 views

Category:

Documents


0 download

DESCRIPTION

Fibonaccio y factorial en java 8

TRANSCRIPT

import java.util.Scanner;public class Deber_1{public static void main(String[ ] arg) {boolean rep = true;while (rep){int numero = 0;char repetir = 'n';Scanner entrada = new Scanner (System.in);System.out.println ("Ingrese la posicion del factor que desea calcular ");numero = entrada.nextInt();System.out.println("El elemento de la serie de Fibonacci en la posicion " + numero + " es " + fib(numero));System.out.println("El factorial de " + numero + " es " + fac(numero));System.out.println("Desea reptir el programa? pulse s para repetir");repetir = entrada.next().charAt(0);if (repetir != 's'){rep = false;}}}public static int fib(int num){int n1, n2, n3;n1 = 0;n2 = 1;n3 = 0;for (int i = 1; i < num ; i++){n3 = n1 + n2;n1 = n2;n2 = n3;}return (n1);}public static int fac(int num){int n1;n1 = 1;for (int i = 1; i