Guest User

Untitled

a guest
Dec 12th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public class Test {
  2. public static void main(String args[]) {
  3. int n;
  4. do {
  5. Scanner scan = new Scanner(System.in);
  6. System.out.print("Введите факториал натурально числа n : ");
  7. n = scan.nextInt();
  8. int result = 1;
  9. for (int i = 2; i <= n; i++)
  10. result *= i;
  11. System.out.println(result);
  12. if (n == 0 || n == 1)
  13. System.out.println(result);
  14. if(n < 0)
  15. System.out.println("Вы ввели отрицательный факториал!");
  16. } while (n < 0);{System.out.println("Конец");}
  17. }
  18. }
  19.  
  20. int n = 0;
  21. while (true) {
  22. try {
  23. Scanner scan = new Scanner(System.in);
  24. System.out.print("Введите факториал натурально числа n : ");
  25. n = scan.nextInt();
  26. break;
  27. } catch (java.util.InputMismatchException e) {
  28. System.out.println("Некорректный ввод!");
  29. }
  30. }
  31. do {
  32. int result = 1;
  33. for (int i = 2; i <= n; i++) result *= i;
  34. System.out.println(result);
  35. if (n == 0 || n == 1) System.out.println(result);
  36. if (n < 0) System.out.println("Вы ввели отрицательный факториал!");
  37. } while (n < 0);
  38. System.out.println("Конец");
Add Comment
Please, Sign In to add comment