Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. /*
  2.  * Dado um número natural diferente de 0, o loop fatora cada número em
  3.  * sequência e imprime o resultado no prompt.
  4.  * Equação: n! = n * (n - 1) * (n - 2) * ...
  5.  *
  6.  */
  7.  
  8. class Main {
  9.     public static void main (String[] args) {
  10.         int x;
  11.         long f, last;
  12.         last = 0;
  13.         for (int i = 0; i <= 10; ++i) {
  14.             x = i; f = i;
  15.             if (x == 0 || x == 1) {
  16.                 System.out.println("1");
  17.             } else {
  18.                 while (x > 1) {
  19.                     f *= (x - 1);
  20.                     if (f == last)
  21.                         break;
  22.                     else
  23.                         System.out.println(f);
  24.                     last = f;
  25.                     --x;
  26.                 }
  27.             }
  28.             System.out.println("---");
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement