Advertisement
robeeeert

Proyecto 1 - ejercicio 1

Apr 12th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Programa1 {
  4.     public static void main(String[] args) {
  5.         int numero;
  6.         int factorial = 1;
  7.         int contador = 2;
  8.         Scanner entrada = new Scanner(System.in);
  9.         System.out.println("-FACTORIAL DE UN NUMERO-");
  10.         System.out.println("Ingrese un numero entero");
  11.         numero = entrada.nextInt();
  12.         //while(contador <= num) {
  13.             //factorial *= contador;
  14.             //contador ++;
  15.         //}
  16.         //if(numero == 0 && numero == 1){
  17.             //System.out.println("Por Defenicion");
  18.             //System.out.println("0! = 1 y 1! = 1");
  19.            
  20.         //}else {
  21.             for(int i = numero; i>0; i--) {
  22.                 factorial *= i;
  23.             }
  24.         //}
  25.         if(numero > 1) {
  26.             System.out.println("\tRESULTADO");
  27.             System.out.println("\t" + numero + "! = "  + factorial);
  28.         }else {
  29.             System.out.println("Por Defenicion");
  30.             System.out.println("0! = 1 y 1! = 1");
  31.         }
  32.     }
  33.  
  34. }
  35.  
Tags: Java Factorial
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement