Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.InputMismatchException;
  2. import java.util.Scanner;
  3.  
  4. public class fun01_7 {
  5.     public static void main(String[] args) {
  6.         int numero = leerEntero("Introduce un numero");
  7.         int resultado = vectorial(numero);
  8.         System.out.println("El vectorial de "+numero+" es: "+resultado);
  9.     }
  10.    
  11.     public static int vectorial(int num) {
  12.         int calc=1;
  13.         for(int i=num; i>0; i--) {
  14.             calc*=i;
  15.         }
  16.         return calc;
  17.     }
  18.    
  19.     public static int leerEntero(String mensaje) {
  20.         int num=0;
  21.         Scanner t = new Scanner(System.in);
  22.         System.out.println(mensaje);
  23.         try {
  24.             num = t.nextInt();
  25.         } catch(InputMismatchException e) {
  26.             num = 0;
  27.         }
  28.         return num;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement