我做了javafx应用程序,显示两个整数的gcd,我必须做一个循环,我使用while循环 但我有一个问题,我不能显示该循环的结果 我得到的错误是“无法解析符号t6”和“无法解析符号t4” 这是代码
package sample;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable {
int q, r1, r2, r3, r4, r;
private Main main;
private Stage primaryStage;
public void setMain(Main main, Stage primaryStage) {
this.main = main;
this.primaryStage = primaryStage;
}
@FXML
private Label label;
@FXML
private TextFlow tf;
@FXML
private TextArea ta;
@FXML
private Text t;
@FXML
private TextField field;
@FXML
private TextField field1;
@FXML
private void handleButtonAction(ActionEvent event) {
String t1 = field.getText();
String t2 = field1.getText();
r1 = Integer.parseInt(t1);
r2 = Integer.parseInt(t2);
if (r1 < r2) {
r3 = r2;
r4 = r1;
r = r3 % r4;
q = r3 / r4;
String t = ("r1=" + r3 + " " + "r2=" + r4 + " " + "q=" + q + " " + "r=" + r);
while (r != 0) {
r3 = r4;
r4 = r;
r = r3 % r4;
q = r3 / r4;
String t6 = "r1=" + r3 + " " + "r2=" + r4 + " " + "q=" + q + " " + "r=" + r;
}
String t7 = ("gcd=" + r4);
label.setText(t+t6+t7);
} else {
r = r1 % r2;
q = r1 / r2;
String t3 = ("r1=" + r1 + " " + "r2=" + r2 + " " + "q=" + q + " " + "r=" + r);
while (r != 0) {
r1 = r2;
r2 = r;
r = r1 % r2;
q = r1 / r2;
String t4 = ("r1=" + r1 + " " + "r2=" + r2 + " " + "q=" + q + " " + "r=" + r);
}
String t5 = ("gcd=" + r2);
label.setText(t3+t4+t5);
}
field.clear();
field1.clear();
}
public void close(){
primaryStage.close();
}
@Override
public void initialize(URL url, ResourceBundle rb){}
public void changeWindow(){
main.secondWindow();
}
}
答案 0 :(得分:1)
String t4的范围只是while循环,只是将它声明为循环并且它将起作用。