java - 解析时到达文件末尾

标签 java 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
}

关于java - 解析时到达文件末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28970520/

相关文章:

Java解析文本文件

java - 解析错误 - 线程 "AWT-EventQueue-0"中出现异常

java - Play Framework 2.4.x 在回调函数中执行保存操作

java - 自定义 ListView 文本颜色未更改

excel - 按月在美国所有州的 Excel 中获得最高排名的最简单方法?

java - 如何将 "2021-11-20+01:00"格式的日期字符串解析为 ZonedDateTime - 错误

python - 解析站点中的表

java - 使用 Raster 创建图像时出现 ArrayIndexOutOfBoundsException

java - 将 double 值 0.9 转换为 long 时如何得到 1?

java - JPA:多个表对应一个实体