Advertisement
Guest User

8labdopzad

a guest
May 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. package com.company;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8.  
  9. import java.math.BigInteger;
  10. public class Main {
  11.     public static void main(String[] args) {
  12.         Pattern l = Pattern.compile("^\\d{1,2}|100$");
  13.         JLabel l1;
  14.         JFrame Window = new JFrame("Вычисление факториала");
  15.         JPanel panel = new JPanel();
  16.         panel.setLayout(new GridLayout(5,1));
  17.         l1 = new JLabel();
  18.         l1.setText("Введите натуральное число");
  19.         JTextField aF = new JTextField();
  20.         JButton ready = new JButton();
  21.         JButton canc = new JButton();
  22.         JLabel Res = new JLabel();
  23.         ready.setText("Решить");
  24.         canc.setText("Отмена");
  25.         ready.addActionListener(e -> {
  26.             long a;
  27.             BigInteger factorial = BigInteger.valueOf(1);
  28.  
  29.             a = Long.parseLong(aF.getText());
  30.             if(a < 0)
  31.                 Res.setText("Число меньше нуля");
  32.             if (a == 0 || a == 1)
  33.                 Res.setText("Факториал= "+a);
  34.             for (int i = 2; i <= a; i++) {
  35.                 factorial = factorial.multiply(BigInteger.valueOf(i));
  36.                 if (i >= a)
  37.                     Res.setText("Факториал= " + factorial);
  38.             }
  39.  
  40.         });
  41.         canc.addActionListener(e -> {
  42.             canc.setVisible(false);
  43.             System.exit(0);
  44.         });
  45.  
  46.         panel.add(l1);
  47.         panel.add(aF);
  48.         panel.add(ready);
  49.         panel.add(canc);
  50.         panel.add(Res);
  51.         Window.add(panel);
  52.         Window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  53.         Window.setSize(300, 250);
  54.         Window.setVisible(true);
  55.  
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement