Results 1 to 5 of 5
  1. #1
    Taszk is offline Member
    Join Date
    May 2011
    Posts
    29
    Rep Power
    0

    Default "illegal start of expression" killing me help please.

    I haven't finished my program but i tried to compile it and i can't seem to figure out why I'm getting "illegal start of expression" at the end of my program for a method that i made called 'areaFORMULA'. Thanks in advance.

    Java Code:
    import java.util.*;
    public class FinalProject
    	{public static void main(String[] args)
    		{int a, b, c;
    			System.out.println("Enter the length of side \"a\" of the triangle to begin:");
    			Scanner in=new Scanner(System.in);
    			a=in.nextInt();
    			b=in.nextInt();
    			c=in.nextInt();
    			
    			
    			if(a==0)
    				{System.exit(0);
    				}
    			while(a!=0)
    				{areaFORMULA();
    				perimeter();
    				
    				
    				if(a==b==c)
    					{System.out.print("According to the given sides, since a,b and c are equal ");
    					System.out.print("the triangle is an Equilateral triangle with an Area of "+area+" and Perimeter of "+p);
    					}
    				if(a==b||a==c||b==c)
    					{System.out.print("According to the given sides, since two sides are equal ");
    					System.out.print("the triangle is an Isosceles triangle with an Area of "+area+" and Perimeter of "+p);
    					}
    				if(a!=b!=c)
    					{System.out.print("According to the given sides, since a,b and c are not equal ");
    					System.out.print("the triangle is a Scalene triangle with an Area of "+area+" and Perimeter of "+p);
    					}
    					}
    	public static void areaFORMULA()
    		{double s = 0.5 * (a + b + c);
    		double area = Math.sqrt(s*(s-a)*(s-b)*(s-c));
    		}
    		
    	public static void perimeter()
    		{p = a+b+c;
    		}
    	}
    }
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    You style (indentation, bracket placement etc) sucks the big one! It makes your code very hard to read. The most likely causes of your problem is that you have a method inside another method, method inside an if or while. Basically your brackets do not match or out of order. If your style was more consistent it would be easier to see where the problem is.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    Java Code:
        if(a!=b!=c) {
            System.out.print("According to th....
            System.out.print("the triangle ....
        } // end of if
    } // end of while
    
    public static void areaFORMULA() // inside main method
    As I suspected.

  4. #4
    Taszk is offline Member
    Join Date
    May 2011
    Posts
    29
    Rep Power
    0

    Default

    Lol this isn't my usual style i wanted to try something different but it really screwed me up i changed everything back to the way i usually use my brackets and indentation. Thanks for your help.

  5. #5
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Apart from your brackets and indentation there are so many other problems as well.

    Like variables scopes, variable declaration, if statement conditions etc etc... Try to resolve them as well.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

Similar Threads

  1. Error: "Illegal start of expression"
    By mokitooo_1994 in forum New To Java
    Replies: 5
    Last Post: 05-12-2011, 09:42 PM
  2. illegal start of expression
    By minusten in forum New To Java
    Replies: 1
    Last Post: 05-03-2011, 04:46 AM
  3. "illegal start of expression"
    By 3RDofApril in forum AWT / Swing
    Replies: 2
    Last Post: 11-04-2010, 01:39 AM
  4. Need help with illegal start of expression
    By WhopperMan in forum New To Java
    Replies: 4
    Last Post: 10-10-2010, 02:58 AM
  5. Replies: 5
    Last Post: 03-20-2009, 10:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •