1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

JAVA: Illegal start of expression

Discussion in 'Software Development' started by rover233, Nov 3, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. rover233

    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));
    
               }
           }
    
        }
    
    }
    
     
  2. andythepandy

    andythepandy

    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
     
  3. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    Apart from that, don't you think that the calculation(d=b*b-4*a*c) should go inside MORE brackets?
     
  4. andythepandy

    andythepandy

    Joined:
    Jul 2, 2006
    Messages:
    379
    Technically it's fine with order of operations, but definitely for readability you should use more brackets
     
  5. sepala

    sepala

    Joined:
    May 20, 2010
    Messages:
    4,038
    :)(y)
     
  6. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1025336

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice