解析时到达文件末尾

reached end of the file while parsing

我是 java 编程新手。我试图编写将温度从华氏度转换为摄氏度或反之的代码,但在解析错误时我到达了文件末尾。所以我应该怎么做才能解决它

package fahrenheittocelsius;

import java.util.Scanner;

public class Fahrenheittocelsius
{



    public static void main(String[] args)
    {
        String firstchoice ;
        String ftc ="fahrenheit to celsuis" ;
        String ctf = "celsius to fahrenheit";

        System.out.println("Do you want to convert from  'fahrenheit to celsuis' or 'celsius to fahrenheit' ");

        Scanner firstscan = new Scanner(System.in);


        firstchoice = firstscan.nextLine();

        if (firstchoice.equals(ftc) );
        {




        System.out.println("Write in the temperature in Fahrenheit that you want to convert it to celsius ");

        Scanner scan1 = new Scanner(System.in);

        double f ;

        f = scan1.nextDouble();

        double c ;

        c= (5/9.0)* (f-23) ;

        System.out.println("the temperature in celsius is " + c );

        }

         if (firstchoice.equals(ctf) );
        {




        System.out.println("Write in the temperature in celsuis that you want to convert it to fahrenheit ");

        Scanner scan2 = new Scanner(System.in);

        double CC ;

        double FF ;

        CC = scan2.nextDouble();

        FF= (CC * 2) + 30 ;

        System.out.println("the temperature in celsius is " + FF);

  }

 }

这意味着您忘记了 } 某处。

我数了 4 个左大括号,但只有 3 个右大括号。寻找你错过的地方。

此外,删除 if 语句后的分号。

if(someCondition){
    //do stuff
}

不是

if(someCondition);{
    //do stuff
}

你的第二个 if 没有结尾}

还有建议,不要让用户写字符串,而是让他写 int。 1 表示摄氏度到华氏度,2 表示华氏度 - 摄氏度。 while 语句中的 switch 和 case 使此类程序更易于理解。可以加个case 0退出结束程序。