Ali Zgheib
Ali Zgheib

Reputation: 15

reached end of the file while parsing

I am new to java programming. I was trying to write a code that convert temperature from Fahrenheit to Celsius or vice versa , and I am getting reached end of the file while parsing error . so what should I do to fix it

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

  }

 }

Upvotes: 0

Views: 734

Answers (2)

Alan
Alan

Reputation: 379

Your second if doesn't have a closing }

Suggestion also, instead of making the user write Strings, make him write int. 1 for Celsius to Fah, 2 for Fah - Celsius. Switch and cases in a while statement make this type of programs more understandable. You can add a case 0 to exit and end the program.

Upvotes: 1

user4205830
user4205830

Reputation:

This means you've forgotten a } somewhere.

I count 4 opening curly braces, but only 3 closing braces. Look for where you missed one.

Also, remove the semi-colons after your if statements.

if(someCondition){
    //do stuff
}

not

if(someCondition);{
    //do stuff
}

Upvotes: 2

Related Questions