Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.InputMismatchException;
- import java.util.Scanner;
- public class fun01_7 {
- public static void main(String[] args) {
- int numero = leerEntero("Introduce un numero");
- int resultado = vectorial(numero);
- System.out.println("El vectorial de "+numero+" es: "+resultado);
- }
- public static int vectorial(int num) {
- int calc=1;
- for(int i=num; i>0; i--) {
- calc*=i;
- }
- return calc;
- }
- public static int leerEntero(String mensaje) {
- int num=0;
- Scanner t = new Scanner(System.in);
- System.out.println(mensaje);
- try {
- num = t.nextInt();
- } catch(InputMismatchException e) {
- num = 0;
- }
- return num;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement