【问题标题】:reached end of the file while parsing解析时到达文件末尾
【发布时间】:2015-03-11 01:53:27
【问题描述】:

我是 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);

  }

 }

【问题讨论】:

  • 请在问题中包含您遇到的完整错误。
  • 您缺少结束语}。如果你愉快地格式化你的代码,你会发现这很容易被发现。如果您没有使用可以为您格式化代码并适当缩进的 IDE 或编辑器,我建议您现在就开始。
  • 嗨 celeo,我正在使用 netbeans,在最后一行出现一个红点,它说在解析时到达了文件的末尾,我不知道这是什么意思,我应该怎么做才能修复它。 ..
  • 乔恩我应该把丢失的地方放在哪里}
  • 阿里,你觉得应该去哪里?学习编程的一部分是解决问题。查找您将{ 放在哪里,并找出} 应该放在哪里。

标签: java parsing


【解决方案1】:

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

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

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

if(someCondition){
    //do stuff
}

不是

if(someCondition);{
    //do stuff
}

【讨论】:

  • 我做到了,谢谢你的时间,感谢艾伦的建议
【解决方案2】:

你的第二个 if 没有结束 }

还建议,不要让用户写字符串,而是让他写 int。 1 代表摄氏到华氏,2 代表华氏 - 摄氏。 while 语句中的 switch 和 case 使这种类型的程序更容易理解。您可以添加一个case 0来退出并结束程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多