Advertisement
QwarkDev

lab 1 / java

Sep 1st, 2020
1,836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1.  
  2. package com.company;
  3.  
  4. import java.io.*;
  5. import java.lang.String;
  6.  
  7. public class Main
  8. {
  9.     static double factorial(int t)
  10.     {
  11.         float result = 1;
  12.  
  13.         for (int i = 1; i < t; i++)
  14.         {
  15.             result = result + result * i;
  16.         }
  17.  
  18.         return result;
  19.     }
  20.  
  21.     public static void main(String[] args)
  22.     {
  23.         String input = "";
  24.  
  25.         try {
  26.             System.out.print("Введите число: ");
  27.             java.io.BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  28.             input = in.readLine();
  29.         } catch (Exception ignored) { }
  30.  
  31.         System.out.print("Факториал: ");
  32.         System.out.println(factorial(Integer.parseInt(input)) + "\n");
  33.         main(args);
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement