sách gpt4 ai đã đi

Vấn đề với việc thực hiện vòng lặp while

In lại 作者:行者123 更新时间:2023-11-30 08:28:25 hai mươi bốn 4
mua khóa gpt4 Nike

此代码用于基本杂货计算器的按钮。当我按下按钮时,一个输入对话框会显示您输入商品价格的位置。我遇到的问题是我无法弄清楚如何获得 do ... while 循环以使输入对话框在输入后弹出。

我希望它始终恢复正常,除非用户选择什么都没有确定或取消,在这种情况下,循环应该中断并填充剩余的框。使用当前代码,我每次都必须按下按钮以手动恢复对话框。我一直在玩弄不同的 while 条件和 if 语句,但我似乎无法让它工作。我是初学者,很抱歉,如果这很简单,谢谢您的宝贵时间。

注意:我故意将 while 条件留空,只是为了显示我需要它的地方。

  NumberFormat numForm = NumberFormat.getCurrencyInstance();
double itemPrice;
double tax;

LÀM {
String s = (String)JOptionPane.showInputDialog("Enter item price:");
if (s == null || s.equals("")) {
double subtotal = getPurchase();
double total;
tax = subtotal * .065;
txtTax.setText(numForm.format(tax));
total = tax + subtotal;
txtTotal.setText(numForm.format(total));
} khác {
thử {
itemPrice = Double.parseDouble (s);
recordPurchase(itemPrice);
txtPrice.setText(numForm.format(itemPrice));

double subtotal = getPurchase();

txtSubtotal.setText(numForm.format(subtotal));
int items = getItems();
String totalItems = Integer.toString(items);
txtItems.setText(totalItems);

} // end try
catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "You must enter numeric data only!");
} // end catch
} // end if Else
}// end do
while();

1 Câu trả lời

您在 while 语句中放置了一个条件。如果条件为真,它将继续迭代。

String s = "";
LÀM
{
s = (String)JOptionPane.showInputDialog("Enter item price:");
if (s == null || s.equals(""))
{
...
}
...
}while(s != null || !s.equals(""));

关于java - 做 while 循环问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20205316/

hai mươi bốn 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com