Skip to content

Instantly share code, notes, and snippets.

@LisGein
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LisGein/c59d73a23430538d4f06 to your computer and use it in GitHub Desktop.
Save LisGein/c59d73a23430538d4f06 to your computer and use it in GitHub Desktop.
import javax.swing.*;
import java.awt.*;
public class task5
{
public static void main(String[] args)
{
JFrame f = new JFrame();
InputPanel ip = new InputPanel();
int res = JOptionPane.showConfirmDialog(f, ip, "Enter data",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (res == JOptionPane.OK_OPTION)
System.exit(0);
else System.exit(0);
}
static int fact(int e)
{
if (e == 1)
return 1;
else if (e == 2)
return 2;
else
return fact(e - 1) * e;
}
static int fib(int r)
{
if (r == 1 || r == 2 || r == 3)
return 1;
return fib(r - 2) + fib(r - 1);
}
static class InputPanel extends JPanel
{
public InputPanel()
{
super(new GridBagLayout());
String input = JOptionPane.showInputDialog("введите число n");
int n = Integer.parseInt(input);
int r = fib(n);
int e = fact(n);
JLabel lblFN = new JLabel("Факториал = ");
JLabel lblLN = new JLabel("Производная = ");
JLabel q = new JLabel(String.valueOf(e));
JLabel y = new JLabel(String.valueOf(r));
add(lblFN, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 5), 0, 0));
add(q, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
add(lblLN, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0));
add(y, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.WEST,
GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment