Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package it.unitn.disi.lingprog.fmi;
- import javafx.application.Application;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.VBox;
- import javafx.scene.text.Font;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- public class FMI extends Application {
- int a, b;
- static Text t = new Text();
- @Override
- public void start(Stage primaryStage) {
- t.setFont(Font.font(22));
- Text t1 = new Text("(");
- t1.setFont(Font.font(22));
- TextField i1 = new TextField();
- Text t2 = new Text(", ");
- t2.setFont(Font.font(22));
- TextField i2 = new TextField();
- Text t3 = new Text(")");
- t3.setFont(Font.font(22));
- Button btn = new Button("Calcola");
- HBox primariga = new HBox(t1, i1, t2, i2, t3, btn);
- btn.setOnAction(event -> {
- a = Integer.parseInt(i1.getText());
- b = Integer.parseInt(i2.getText());
- mcd(a, b);
- });
- VBox root = new VBox(primariga, t);
- Scene scene = new Scene(root, 600, 200);
- primaryStage.setTitle("Fondamenti Matematici per l'Informatica");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- static void mcd (int x, int y){
- final int cx = x;
- final int cy = y;
- int q, r = 1, snext, sprev = 1, scur = 0, tprev = 0, tcur = 1, tnext;
- while(r != 0) {
- q = x / y;
- r = x % y;
- if(r != 0){
- snext = sprev - q * scur;
- tnext = tprev - q * tcur;
- x = y; y = r;
- sprev = scur; scur = snext;
- tprev = tcur; tcur = tnext;
- }
- }
- System.out.println("("+cx+", "+cy+") = "+y+", x = "+scur+", y = "+tcur+"");
- t.setText("("+cx+"; "+cy+") = "+y+"; x = "+scur+"; y = "+tcur+"");
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement