gpt4 book ai didi

java - 解析时到达文件末尾

转载 作者:行者123 更新时间:2023-12-01 22:24:57 25 4
gpt4 key购买 nike

我是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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com