Advertisement
robeeeert

Problema 1 proyecto1

Apr 12th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. /*
  2.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  3.  */
  4.  
  5. package com.mycompany.problema1;
  6.  
  7. /**
  8.  *
  9.  * @author ianto
  10.  */
  11. import java.util.*;
  12. public class Problema1 {
  13.  
  14.     public static void main(String[] args) {
  15.         int numero;
  16.         int factorial = 1;
  17.         int contador = 2;
  18.         Scanner entrada = new Scanner(System.in);
  19.         System.out.println("-FACTORIAL DE UN NUMERO-");
  20.         System.out.println("Ingrese un numero entero");
  21.         numero = entrada.nextInt();
  22.         for(int i = numero; i>0; i--) {
  23.              factorial *= i;
  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. }
Tags: Java Factorial
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement