Results 1 to 5 of 5
- 05-27-2011, 07:40 AM #1
Member
- Join Date
- May 2011
- Posts
- 29
- Rep Power
- 0
"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; } } } }
- 05-27-2011, 07:46 AM #2
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.
- 05-27-2011, 07:48 AM #3
As I suspected.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
- 05-27-2011, 08:15 AM #4
Member
- Join Date
- May 2011
- Posts
- 29
- Rep Power
- 0
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.
- 05-27-2011, 08:21 AM #5
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.
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
Similar Threads
-
Error: "Illegal start of expression"
By mokitooo_1994 in forum New To JavaReplies: 5Last Post: 05-12-2011, 09:42 PM -
illegal start of expression
By minusten in forum New To JavaReplies: 1Last Post: 05-03-2011, 04:46 AM -
"illegal start of expression"
By 3RDofApril in forum AWT / SwingReplies: 2Last Post: 11-04-2010, 01:39 AM -
Need help with illegal start of expression
By WhopperMan in forum New To JavaReplies: 4Last Post: 10-10-2010, 02:58 AM -
How do you start a Java program from the "Start" menu under Windows?
By ScottVal in forum New To JavaReplies: 5Last Post: 03-20-2009, 10:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks