Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java程序中存在字符串和编译错误_Java_String_Input - Fatal编程技术网

Java程序中存在字符串和编译错误

Java程序中存在字符串和编译错误,java,string,input,Java,String,Input,我试着编译这个,但得到了一个错误:$javacquestion2.java2>&1 问题2.java:55:错误:解析时到达文件末尾 } ^ 1错误类型无法解析为变量 我很确定代码是正确的,但有一点我遗漏了。该程序旨在检查机票类型(标准/贵宾/受限)和折扣(无/学生/养老金领取者),如果选择vip,则没有折扣,学生和养老金领取者分别有5%和10%的折扣,但我无法整理输入方法或类型声明 感谢您的任何帮助。 另外,我是一名正在学习Java的学生,似乎无法找到这个问题的确切解决方案,因此我在这里发布了

我试着编译这个,但得到了一个错误:$javacquestion2.java2>&1 问题2.java:55:错误:解析时到达文件末尾 } ^ 1错误类型无法解析为变量

我很确定代码是正确的,但有一点我遗漏了。该程序旨在检查机票类型(标准/贵宾/受限)和折扣(无/学生/养老金领取者),如果选择vip,则没有折扣,学生和养老金领取者分别有5%和10%的折扣,但我无法整理输入方法或类型声明

感谢您的任何帮助。 另外,我是一名正在学习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!");
    }

您的
问题2
课程缺少一个大括号结尾:

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.equals("standard")) && (type.equals("student"))) {
      double standard_student = standard * 0.95;
    }

    if ((ticket.equals("standard")) && (type.equals("pensioners"))) {
      double standard_pensioners = standard * 0.90;
    }

    if ((ticket.equals("restricted")) && (type.equals("student"))) {
      double restricted_students = restricted * 0.95;
    }


    if ((ticket.equals("restricted")) && (type.equals("pensioner"))) {
      double restricted_pensioner = restricted * 0.90;
    }

    if (ticket.equals("standard"))
      System.out.print("Your ticket costs $.");

    if (ticket.equals("restricted"))
      System.out.print("Your ticket costs $.");

    if (ticket.equals("VIP"))
      System.out.print("Your discount type cannot be used with your requested ticket type.");

    System.out.println ("Thank you!");
  }
} // <--- Add this
import java.util.Scanner;
公开课问题2{
公共静态void main(字符串参数[]){
扫描仪用户输入=新扫描仪(System.in);
串票;
系统输出打印(“票证类型:”);
ticket=userinput.next();
字符串折扣;
System.out.print(“您有什么折扣?”);
折扣=用户输入。下一步();
国际标准=40;
int=20;
int-VIP=60;
如果((票证等号(“标准”)&(类型等号(“学生”)){
双标准学生=标准*0.95;
}
if((票证等额(“标准”)和&(类型等额(“养老金领取者”)){
双标准养老金领取者=标准*0.90;
}
如果((票证等额(“限制”)&(类型等额(“学生”)){
双重限制学生=限制*0.95;
}
如果((票证等额(“限制”)&(类型等额(“养老金领取者”)){
双重限制养老金领取者=限制*0.90;
}
if(票证相等(“标准”))
System.out.print(“您的机票费用为美元”);
if(票证相等(“受限”))
System.out.print(“您的机票费用为美元”);
if(票证相等(“VIP”))
System.out.print(“您的折扣类型不能与您请求的票证类型一起使用。”);
System.out.println(“谢谢!”);
}

}//在比较字符串的值时,始终使用equals方法,而不是==


例如:如果(type.equals(“student”)

首先,您忘记了班级的结束语
}
。其次,将字符串值与
string
equals
方法进行比较,而不是与
=
进行比较。有关Targetman注释的第二部分,请参阅