编写了以下几行代码,旨在将 2 个值插入到对话框中,并分配给 2 个不同的变量。假设我插入 22,那么它应该在文本字段中显示为 2x2 = 4,相反,它会打印类似 50 x 50 = 2500 的内容。
String a = JOptionPane.showInputDialog("Qual cálculo deseja fazer? (AB = A x B)", "AB");
aNum = a.charAt(0);
bNum = a.charAt(1);
int cNum = aNum*bNum;
Game.getNumbers(aNum, bNum);
JOptionPane.showInputDialog(aNum, bNum);
TF1.setText(Game.First() +" x "+ Game.Second() +" = "+ cNum);
涉及班级:
public class Game1 {
private int first = 0;
private int second = 0;
private int score = 0;
private int hiScore = 0;
public void numTotalCheck(int a){
String option1 = null;
char option = 0;
do{
if (a == (first*second)){
JOptionPane.showMessageDialog(null, "Parabéns. Você acertou!");
score = score + 100;
if(score > hiScore){
hiScore = score;
}
}else{
score = score - 100;
if(score > hiScore){
hiScore = score;
}
JOptionPane.showMessageDialog(null, "Errado!");
option1 = JOptionPane.showInputDialog("Deseja jogar novamente? <S/N>");
option = option1.charAt(0);
}
}while((option == 's') || (option == 'S'));
}
public void getNumbers(int a, int b){
first = a;
second = b;
}
public int First(){
return first;
}
public int Second(){
return second;
}
结果:
不负相思意
HUWWW
相关分类