java - 如果客户支付的费用低于票价
问题描述
帮帮我,我试过成功,程序但这里有错误可以吗?哪位解决后发送,如果客户支付的低于票价,我想打印低于票价的钱并打印剩余的支付,或者如果客户支付的超过票价,剩下的钱打印给客户,最后如果他支付了票款,你打印欢迎
import java.util.Scanner;
public class Flow {
static Scanner input = new Scanner(System.in);
static int age;
static double ticketpricetax = 0.15 * 100 + 10;
public static double remainigamount = ticketpricetax;
public static double howmuchpay = 10;
public static void main(String[] args) {
System.out.println("Age");
int age = input.nextInt();
if (age > 12 || age <= 50) {
System.out.println("ticket price is ");
System.out.println(ticketpricetax);
System.out.println("Please pay your ticket");
}
input.nextInt();
if (ticketpricetax > howmuchpay) {
System.out.println("the money less than ticket price");
} else if (ticketpricetax > howmuchpay) {
System.out.println("the money is greater than ticket price");
} else {
System.out.println("welcome");
}
}
}
解决方案
您的价格输入未存储在任何变量中,它应该是 double 而不是 int,然后您将 ticketpricetax 和 howmuchpay 与其初始化值进行比较,howmuchpay 不会随输入更新。此外,您进行了不正确的检查并遗漏了一些陈述。这是更正:
import java.util.Scanner;
public class Flow {
static Scanner input = new Scanner(System.in);
static int age;
static double ticketpricetax = 0.15 * 100 + 10;
public static double howmuchpay = 10;
public static void main(String[] args) {
System.out.println("Age");
int age = input.nextInt();
if (age > 12 || age <= 50) {
System.out.println("ticket price is ");
System.out.println(ticketpricetax);
System.out.println("Please pay your ticket");
}
howmuchpay = input.nextDouble();
if (ticketpricetax > howmuchpay) {
System.out.println("the money less than ticket price");
System.out.println("rest of the money to pay = "+(ticketpricetax-howmuchpay));
} else if (ticketpricetax < howmuchpay) {
System.out.println("the money is greater than ticket price");
System.out.println("rest of the money = "+(howmuchpay-ticketpricetax));
} else {
System.out.println("welcome");
}
}
}
推荐阅读
- flutter - Flutter 结合了futuerbuilder和streambuilder
- python - Python Pandas Dataframe 存储下一行值
- python - 分别对 HTTPRequest 和 HTTPResponse 的原始请求和响应
- ios - 如何快速获取带有 URL 的 JS 事件处理程序
- html - 如何实现 HTML5 模式以仅接受特定字符
- excel - 多列作为一个范围 - Worksheet_Change - 条件格式的替代方案
- android - 如何使用 RecyclerView 的 SmoothScrollToPosition 滚动并在 recyclerview 中使用动态位置?
- nosql - 具有一对多关系和选择分区键的 NoSQL 数据库设计
- javascript - 我将如何在此列表中显示每个人员选择器的标题
- asp.net - 如何使用 FromBody 发布 json