JAVA: Illegal start of expression

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

rover233

Thread Starter
Joined
Nov 3, 2011
Messages
1
Hi, I'm new to java, trying to work with quadratic equation simple program, after running "Illegal start of expression" error appears.

Thanks

Code:
public class QuadraticEquation {
 
    public static void main(String[] args) {
        // TODO code application logic here

       double a=0.5, b=-2.7, c=3.5, d, eps=1e-8;
       if (Math.abs(a)<eps)
       if (Math.abs(b)<eps)
       if (Math.abs(c)<eps)
           System.out.println("Solution is any number");
       else
           System.out.println("No solution");
       else
           System.out.println("x1=x2="+(-c/b));
       else {     // [B]<<<<<---------- This line returns an error[/B] "Illegal start of expression"
       if((d=b**b-4*a*c)<0.0)
       {    
           d=0.5*Math.sqrt(-d)/a;
               a=-0.5*b/a;
               System.out.print("x1="+a+"+i"+d+", x2="+a+"-i"+d);
           } else {
           d=0.5*Math.sqrt(d)/a;
           a=-0.5*b/a;
           System.out.println("x1="+(a+d)+", x2="+(a-d));

           }
       }

    }

}
 
Joined
Jul 2, 2006
Messages
379
Hi and welcome,

You appear to have two asterisks in this line:
Code:
if((d=b**b-4*a*c)<0.0)
Remove the second * and it'll work

Andy
 
Joined
May 20, 2010
Messages
4,040
Apart from that, don't you think that the calculation(d=b*b-4*a*c) should go inside MORE brackets?
 
Joined
Jul 2, 2006
Messages
379
Technically it's fine with order of operations, but definitely for readability you should use more brackets
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top