• A function that calls itself, either directly or indirectly, is a recursive function
  • Both iteration and recursion are based on a control structure: Iteration uses a repetition structure; recursion uses a selection structure.
  • Iteration and recursion each involve a termination test: Iteration terminates when the loop-continuation condition fails; recursion terminates when a base case is recognized
 
Code:

package javafxtemplate1;

//textProperty().addListener Listview Label
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;


/**
*
* @author Manas9
*/
public class JavaFXTemplate1 extends Application {
TextArea textArea= new TextArea ();
String newLine = "\n";static int xx1 ;
@Override
public void start(Stage primaryStage) throws Exception {
//
Group groot1 = new Group();
Label label1 = new Label(); label1.setText("Type anything");
label1.setLayoutX(10);label1.setLayoutY(20);

textArea.setLayoutX(90);textArea.setLayoutY(120);
textArea.setPrefHeight(100);textArea.setPrefWidth(250);
textArea.setPromptText("textarea");
//
TextField textField = new TextField ();
textField .setLayoutX(160);textField .setLayoutY(20);
textField.setPromptText("Enter an Integer");
textField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
//label1.textProperty().bind("Yu entered"+ textField.textProperty());
//textArea.textProperty().bindBidirectional(textField.textProperty());
label1.setText("you Entered "+newValue);
xx1 = Integer.parseInt(newValue);
textArea.appendText("factorials "+String.valueOf(factorial(xx1)));
}
});
groot1.getChildren().addAll(label1, textField, textArea);

//Scene scene = new Scene(groot, 350, 150);
Scene scene = new Scene(groot1, 350, 250);
primaryStage.setScene(scene);
primaryStage.setTitle("Linked Data:: Recursions");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
private int factorial(int n1) {
if (n1==1) {
return n1;
}
else {
textArea.appendText("f-received :: "+ n1+newLine);
return n1 * factorial(n1-1);
}

}
}

/*
Convert using Integer.toString(int)
Convert using String.valueOf(int)
Convert using new Integer(int).toString()
Convert using String.format()
*/

 
Displays: