英文:
If the customer pays less than the ticket price
问题
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("年龄");
int age = input.nextInt();
if (age > 12 || age <= 50) {
System.out.println("票价为 ");
System.out.println(ticketpricetax);
System.out.println("请支付您的票款");
}
input.nextInt();
if (ticketpricetax > howmuchpay) {
System.out.println("支付的金额少于票价");
} else if (ticketpricetax > howmuchpay) {
System.out.println("支付的金额大于票价");
} else {
System.out.println("欢迎光临");
}
}
}
英文:
Help me here i tried make success , program but theres a mistakes here can?
any one solve it and send it ,
If the customer pays less than the ticket price, I want to print the money less than the ticket price and print the rest to pay, or if the customer pays more than the ticket price, the rest of the money is printed to the customer, and finally if he pays the ticket amount, you print welcome
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");
}
}
}
答案1
得分: 1
你的价格输入未存储在任何变量中,应为双精度浮点型而不是整型,然后你正在比较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("年龄");
int age = input.nextInt();
if (age > 12 || age <= 50) {
System.out.println("票价是 ");
System.out.println(ticketpricetax);
System.out.println("请支付您的票款");
}
howmuchpay = input.nextDouble();
if (ticketpricetax > howmuchpay) {
System.out.println("金额少于票价");
System.out.println("剩余需要支付的金额 = " + (ticketpricetax - howmuchpay));
} else if (ticketpricetax < howmuchpay) {
System.out.println("金额大于票价");
System.out.println("剩余的金额 = " + (howmuchpay - ticketpricetax));
} else {
System.out.println("欢迎");
}
}
}
请注意,我已根据你的要求,仅翻译代码部分,其余内容保持不变。
英文:
Your price input is not stored in any variable and it should be double not int, and then you are comparing ticketpricetax and howmuchpay with their initialized values,howmuchpay is not updated with input. In addition you're making an incorrect check and missing some statements.
Here is the correction :
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");
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论