Created
January 16, 2017 17:45
-
-
Save oscarcpozas/9bf95b99256226162aef676e55aaa853 to your computer and use it in GitHub Desktop.
Resuelto 02
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
public class Factorial { | |
public static void main(String[] args) throws IOException { | |
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in)); | |
int num; | |
int factorial = 1; | |
System.out.println("Por favor introduzca un número del 1 al 7:"); | |
boolean valido = false; | |
do { | |
num = Integer.parseInt(buffer.readLine()); | |
if(num <= 100 && num >= 1) { | |
valido = true; | |
} else { | |
System.out.println("El numero introducido no es valido"); | |
} | |
} while (!valido); | |
int numeroIntroducido = num; // Esto es una tonteria, para el system.out del final | |
while (num != 0) { | |
factorial = factorial * num; // Esto se podria abreviar a: factorial *= num; | |
num --; | |
} | |
System.out.println("El factorial de " + numeroIntroducido + " es " + factorial); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment