-2

Wrote some code to find roots of a polynomial via the quadratic formula, but it is reaching the end of the file while parsing. All my curly braces are closed, so I'm not sure where the error is. Can anybody see why?

        public static void main(String[] args){ //execute the previously defined methods to calculate the quadratic equation.
        while (cont){
        Scanner Ascanner = new Scanner(System.in); //Created a new scanner variable for the A value.
        double a = Ascanner.nextInt(); //Storing the next integer of that scanner variable for an Integer of the A value.
        double b = Ascanner.nextInt(); //Storing the next integer of that scanner variable for an Integer for the B value.
        double c = Ascanner.nextInt(); //Storing the next integer of that scanner variable for an Integer of the C value.
        //Finding the radicand
        double tem1 = handleradicand(a,b,c);
        System.out.println("radicand" + tem1);
        //Finding the radical
        if (tem1 <= 0) {
           double tem2 = sub_0rootradicand(tem1);
           System.out.println("radical" + tem2);
           double tem3 = divideBby2a (b,a);
           double tem4 = divideRADby2a (tem2, a);
           double firstX = findroot1 (tem3, tem4);
           double secondX = findroot2 (tem3, tem4);
           System.out.println("Your roots are X = i " + firstX + " " + "and X = i " + secondX);
       }  else {
           double tem2 = rootradicand(tem1);

           System.out.println("radical" + tem2);
           double tem3 = divideBby2a (b,a);
           double tem4 = divideRADby2a (tem2, a);
           double firstX = findroot1 (tem3, tem4);
           double secondX = findroot2 (tem3, tem4);
       }
        system.out.println("Again? (y/n)");
        resp = Ascanner.next();
       if(resp.equalsIgnoreCase("n") || resp.equalsIgnoreCase("y")){
           if(resp.equalsIgnoreCase("n")){
            cont = false;
            } else {
            cont = true;
            }
        }

}

EDIT: Was missing curly braces at the end, fixed.

Gabe Spound
  • 568
  • 5
  • 28

2 Answers2

2

This could happen if your curly parenthesis are not ending completeley or maybe there could be extra parenthesis in the end. So check your opening and closing parenthesis of each functions and class. This might solve your problem. I have experienced this compiler error before and the above solution worked every time.

burglarhobbit
  • 1,860
  • 2
  • 17
  • 32
  • its not my whole code, i have methods defind before that and all of that including the code i showed is within a public class – Gabe Spound Aug 28 '15 at 15:29
  • Yes I just realised that. I was just editing my answer. Try to cross-check your code for what I just said above. – burglarhobbit Aug 28 '15 at 15:35
  • Here is a link which tries to say exactly what I want to, [braces-Solution](http://stackoverflow.com/questions/9679523/reached-end-of-file-while-parsing?rq=1) – burglarhobbit Aug 28 '15 at 15:48
1

I was missing curly braces at the end, fixed

Gabe Spound
  • 568
  • 5
  • 28