gpt4 book ai didi

Java:如何重复输入直到收到所需的输入?

转载 作者:行者123 更新时间:2023-11-30 07:09:53 25 4
gpt4 key购买 nike

我读过很多关于 while 循环等的文章和页面,我只是不明白在哪里放置循环来重复此操作,直到满足三个条件之一。如果有人可以指出我需要添加 while-do 或其他任何内容的地方,我将非常感激,除非您愿意,否则无需打印任何代码。

    System.out.print("Customer name: ");
name=scan.next();
System.out.print("Customer member level: ");
level=scan.next();
if (level.equalsIgnoreCase("Jedi"))
{
System.out.print("Current balance: ");
balance=scan.nextDouble();
System.out.print("Was the payment made late?: ");
late=scan.next();
if (late.equalsIgnoreCase("Yes"))
{
double interestLatePayment=(balance*0.02);
paymentToPrinciple=(balance*0.04);
totalPayment=(interestLatePayment+paymentToPrinciple);
percentToPrinciple=100*(paymentToPrinciple/totalPayment);
percentToInterest=(100-percentToPrinciple);

System.out.println("\nBill for "+level+" customer "+name);
System.out.printf("Card Balance: $%1.2f%n", balance);
System.out.printf("Interest for late payment (2.0%% of principle): $%1.2f%n", interestLatePayment);
System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
}
else if(late.equalsIgnoreCase("No"))
{
double interestLatePayment=(balance*0.01);
paymentToPrinciple=(balance*0.04);
totalPayment=(interestLatePayment+paymentToPrinciple);
percentToPrinciple=100*(paymentToPrinciple/totalPayment);
percentToInterest=(100-percentToPrinciple);

System.out.println("\nBill for "+level+" customer "+name);
System.out.printf("Card Balance: $%1.2f%n", balance);
System.out.printf("Interest for on-time payment (1.0%% of principle): $%1.2f%n", interestLatePayment);
System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
}
}
if (level.equalsIgnoreCase("Padowan"))
{
System.out.print("Current balance: ");
balance=scan.nextDouble();
System.out.print("Was the payment made late?: ");
late=scan.next();
if (late.equalsIgnoreCase("Yes"))
{
double interestLatePayment=(balance*0.028);
paymentToPrinciple=(balance*0.04);
totalPayment=(interestLatePayment+paymentToPrinciple);
percentToPrinciple=100*(paymentToPrinciple/totalPayment);
percentToInterest=(100-percentToPrinciple);
lateFee=10;

System.out.println("\nBill for "+level+" customer "+name);
System.out.printf("Card Balance: $%1.2f%n", balance);
System.out.printf("Interest for late payment (2.8%% of principle): $%1.2f%n", interestLatePayment);
System.out.printf("Late fee: $%1.2f%n", lateFee);
System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
}
else if(late.equalsIgnoreCase("No"))
{
double interestLatePayment=(balance*0.018);
paymentToPrinciple=(balance*0.04);
totalPayment=(interestLatePayment+paymentToPrinciple);
percentToPrinciple=100*(paymentToPrinciple/totalPayment);
percentToInterest=(100-percentToPrinciple);

System.out.println("\nBill for "+level+" customer "+name);
System.out.printf("Card Balance: $%1.2f%n", balance);
System.out.printf("Interest for late payment (1.8%% of principle): $%1.2f%n", interestLatePayment);
System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
}
}
if (level.equals("Youngling"))
{
System.out.print("Current balance: ");
balance=scan.nextDouble();
System.out.print("Was the payment made late?: ");
late=scan.next();
if (late.equalsIgnoreCase("Yes"))
{
double interestLatePayment=(balance*0.035);
paymentToPrinciple=(balance*0.04);
totalPayment=(interestLatePayment+paymentToPrinciple);
percentToPrinciple=100*(paymentToPrinciple/totalPayment);
percentToInterest=(100-percentToPrinciple);
lateFee=20;

System.out.println("\nBill for "+level+" customer "+name);
System.out.printf("Card Balance: $%1.2f%n", balance);
System.out.printf("Interest for late payment (3.5%% of principle): $%1.2f%n", interestLatePayment);
System.out.printf("Late fee: $%1.2f%n", lateFee);
System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
}
else if(late.equalsIgnoreCase("No"))
{
double interestLatePayment=(balance*0.025);
paymentToPrinciple=(balance*0.04);
totalPayment=(interestLatePayment+paymentToPrinciple);
percentToPrinciple=100*(paymentToPrinciple/totalPayment);
percentToInterest=(100-percentToPrinciple);

System.out.println("\nBill for "+level+" customer "+name);
System.out.printf("Card Balance: $%1.2f%n", balance);
System.out.printf("Interest for late payment (2.5%% of principle): $%1.2f%n", interestLatePayment);
System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
}
}
else
{
System.out.print("Invalid member level. Enter valid member level: ");
}
}

}

最佳答案

类似这样的事情:

String input;
do {
input = getNewInput(); //replace this with however you get input, probably a scanner
}while (!input.equals("firstcondition") && !input.equals("secondcondition"))

//then after that do whatever you want to with the input now that you know it matches

关于Java:如何重复输入直到收到所需的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39403565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com