我想在同一个JOptionPane对话框中显示阶乘结果和工作(计算),例如1x2x3x4x5=120和花费的小时数,但还没有找到解决方案。任何帮助都将受到高度的感谢。:)
private fun uploadWithTransferUtility(remote: String, local: File) {
String number = JOptionPane.showInputDialog("Please enter the number below ");
int n = Integer.parseInt(number);
long fact = 1;
int i = 1;
if (n<=0){
JOptionPane.showMessageDialog(null," Please enter a possitive number");
}
else{
while(i<=n)
{
if (i==1){
fact = fact * i;
System.out.print(i);
i++;
}
else{
fact = fact * i;
System.out.print("*"+i);
i++;
}
JOptionPane.showMessageDialog(null,"="+fact);
}发布于 2020-01-30 21:39:03
你可以这样做
int n = Integer.parseInt(number);
long fact = 1;
int i = 1;
if (n <= 0) {
JOptionPane.showMessageDialog(null, " Please enter a possitive number");
} else {
StringJoiner stringJoiner = new StringJoiner("x"); //You can use "*" if you want
for (i = 1; i <= n; i++) {
fact = fact * i;
stringJoiner.add(i + "");
}
JOptionPane.showMessageDialog(null, stringJoiner.toString() + "=" + fact);
}https://stackoverflow.com/questions/59987149
复制相似问题