Results 1 to 5 of 5
  1. #1
    eddyk6's Avatar
    eddyk6 is offline Member
    Join Date
    Jan 2012
    Posts
    4
    Rep Power
    0

    Default Illegal start of expression

    I'm having problems when writing my program it currently says "illegal start of an expression" and "else without if" for another error I was wanting to know what is the correct way to write the code in either a public or private expression. And for the "else without if" I was wanting to know if I'm supposed to be using "else if's" or just "if's"

    My code is in the attachment its a .txt file

    help.txt

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Illegal start of expression

    I saw this somewhere in your code:

    Java Code:
    if (male);
    				{
    					//Not Old Enough
    					if (age < 25);
    						system.out.println("Thank You.\n");
    						system.out.println("The male renter is",(age), "years old.\n");
    						system.out.println("The rate class is: Sorry, the renter is not 25 years of age or older.\n");
    						
    					//Risk Rate 2
    					if (age >= 25 && age <= 32);
    						system.out.println("Thank You.\n");
    						system.out.println("The male renter is",(age),"years old.\n");
    						system.out.println("The rate class is: Risk Rate 2 - $57.00 per day or $285.00 per week.\n");
    						
    					//Best Rate
    					if (age > 32 && age <=65);
    						system.out.println("Thank You.\n");
    						system.out.println("The male renter is",(age),"years old.\n");
    						system.out.println("The rate class is: Best Rate - $40.00 per day or $200.00 per week.\n");
    						
    					//Risk Rate 3
    					if (age >= 66);
    						system.out.println("Thank You.\n");
    						system.out.println("The male renter is",(age),"years old.\n");
    						system.out.println("The rate class is: Risk Rate 3 - $",((age-66)*2)+40.00, "per day or $", ((age-66)*5)+200.00,"per week.\n");
    				
    				}
    Note the trailing semi colons at the end of you if-clauses; it doesn't belong there, because now you have an empty if-statement (a semi colon is an empty statement and a statement terminators symbol). Also, indenting statements doesn't make them a block of statements in Java; you need a pair of { ... } for that purpose (Python can do it the way you did it, but Python was made by a mathematician and we all know what those folks are like ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    eddyk6's Avatar
    eddyk6 is offline Member
    Join Date
    Jan 2012
    Posts
    4
    Rep Power
    0

    Default Re: Illegal start of expression

    Thank you! yea i got rid of the semi colon after (male) and i it did the trick so thanks! yea i did some python but i just mainly did it to keep it ordered and so i can read it easier... do i have to add any {}???

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,419
    Rep Power
    20

    Default Re: Illegal start of expression

    Most members here won't click links. If the code is short enough, post it here, within code tags. If it's too long to post here, it's too long to read.

    Check and match all opening and closing braces {} parentheses () and quote ""

    db

    edit Hmmm...
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Illegal start of expression

    Quote Originally Posted by eddyk6 View Post
    Thank you! yea i got rid of the semi colon after (male) and i it did the trick so thanks! yea i did some python but i just mainly did it to keep it ordered and so i can read it easier... do i have to add any {}???
    Yep, if you want to group statements and make a statement block out of them you have to put { ... } around them, e.g.

    Java Code:
    if (<condition>) {
       statement_1;
       statement_2;
       ...
       statement_n;
    }
    Some people argue that you should always put curly brackets around even a single statement, but I'm not one of them.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Illegal start of expression
    By Robster in forum New To Java
    Replies: 3
    Last Post: 11-26-2011, 07:43 AM
  2. Illegal start of expression
    By lodaSchitt in forum New To Java
    Replies: 2
    Last Post: 04-28-2011, 10:04 PM
  3. Illegal Start of Expression
    By Tyre in forum New To Java
    Replies: 20
    Last Post: 04-15-2011, 02:50 PM
  4. illegal start of expression
    By rajivjoshi in forum New To Java
    Replies: 3
    Last Post: 05-31-2010, 09:12 AM
  5. Illegal start of expression
    By Basit56 in forum New To Java
    Replies: 2
    Last Post: 08-18-2009, 09:12 AM

Tags for this Thread

Posting Permissions

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