我尝试编译这个,并得到一个错误说: $javac Question2.java 2>&1 Question2.java:55: error:达到文件结尾同时解析} ^ 1错误类型不能被解析为变量
我很确定代码是正确的,但是我缺少一点东西。该程序旨在检查机票类型(标准/贵宾/限制)和折扣(无/学生/养老金领取者),如果选择了贵宾,则没有折扣,学生和养老金领取者有5%和10%的折扣分别,但我无法理清输入法或类型声明。
任何形式的帮助表示赞赏。PS,我是一名正在学习 Java 的学生,似乎无法找到解决这个问题的确切方法,因此我在这里发布了一个问题。
import java.util.Scanner;
public class Question2 {
public static void main(String args[]){
Scanner userinput = new Scanner(System.in);
String ticket ;
System.out.print(" Type of Ticket: ");
ticket = userinput.next();
String discount;
System.out.print("What sort of discount do you have?");
discount = userinput.next();
int standard = 40;
int restricted = 20;
int VIP = 60;
if ((ticket == "standard") && (type == "student")) {
double standard_student = standard * 0.95;
}
if ((ticket == "standard") && (type == "pensioners")) {
double standard_pensioners = standard * 0.90;
}
if ((ticket == "restricted") && (type == "student")) {
double restricted_students = restricted * 0.95;
}
if ((ticket == "restricted") && (type == "pensioner")) {
double restricted_pensioner = restricted * 0.90;
}
if (ticket=="standard")
System.out.print("Your ticket costs $.");
if (ticket == "restricted")
System.out.print("Your ticket costs $.");
if (ticket== "VIP")
System.out.print("Your discount type cannot be used with your requested ticket type.");
System.out.println ("Thank you!");
}