Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Illegal start of expression!

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Illegal start of expression!

    I'm new to the forums, I am sorry if I do this incorrectly.

    Here is my code :

    1import java.util.Scanner;
    2
    3public class Lab4b
    4
    5{
    6
    7 public void main ()
    8 {
    9
    10 Scanner input = new Scanner( System.in );
    11
    12 int employee_name;
    13 int hours_worked;
    14 int pay_rate;
    15
    16 System.out.println( "Employee: %d" , employee_name );
    17
    18 if ( hours_worked <= 40 )
    19 System.out.println( "Gross pay: %d", hours_worked*pay_rate );
    20
    21 else
    22 System.out.println( "Gross pay: %d", 1.5*pay_rate*hours_worked );
    23
    24 if (hours_worked <= 40 )
    25 System.out.println( "Withholding Tax: %d", hours_worked*pay_rate*25% );
    26
    27 else
    28 System.out.println( "Withholding Tax: %d", 1.5*pay_rate*hours_worked*25% );
    29
    30 if (hours_worked <= 40 )
    31 System.out.println( "Net Pay: %d", hours_worked*pay_rate - hours_worked*pay_rate*25% );
    32
    33 else
    34 System.out.println( "Net Pay: %d", 1.5*pay_rate*hours_worked - 1.5*pay_rate*hours_worked*25% );
    35
    36
    37 }
    38
    39}






    The error happens at the end of lines 25, 28 , 31 and 34. JDK says that the " ); " at the end of each statement is the problem, however I am unsure.
    Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,108
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Illegal start of expression!

    The println method takes a single argument. The code you posted is giving it more than one arg separated by a comma
    Check that you are using the correct method. There are other printing methods that take more than one arg.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    NoobOfTheMonth (February 11th, 2013)

  4. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Illegal start of expression!

    Which print method should I use? printf produces the same result

  5. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Illegal start of expression!

    Show how you tried to use printf. Also, please post code without line numbers, and please use code tags when posting code.

  6. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,108
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Illegal start of expression!

    Please copy and paste here the full text of the error messages. Put the messages in code tags to preserve the location of the ^.
    Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #6
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Illegal start of expression!

    This is my attempt at printf on the problem areas, thanks!

    if (hours_worked <= 40 )
    	System.out.printf( "Withholding Tax: %d", hours_worked*pay_rate*25% );
     
    	else 
    	System.out.printf( "Withholding Tax: %d", 1.5*pay_rate*hours_worked*25% );
     
    	if (hours_worked <= 40 )
    	System.out.printf( "Net Pay: %d", hours_worked*pay_rate - hours_worked*pay_rate*25% );
     
    	else
    	System.out.printf( "Net Pay: %d", 1.5*pay_rate*hours_worked - 1.5*pay_rate*hours_worked*25% );

    java:31: error: illegal start of expression
    Last edited by NoobOfTheMonth; February 11th, 2013 at 08:36 PM. Reason: added error

  8. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,108
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Illegal start of expression!

    Where is the ^ located in the error message?

    hours_worked*pay_rate*25%
    The % at the end of that arthmetic expression is the modulus operator and needs a numeric value after it to make it a value arithmetic expression.
    For example: hours_worked*pay_rate*25%5

    Why are you putting a modulus operator ( % ) at the end of the expression?
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    NoobOfTheMonth (February 11th, 2013)

  10. #8
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Illegal start of expression!

    I was trying to get 25 percent of the product of those numbers, however I didn't know that the percentage was the problem. I could just use .25, correct?

  11. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,108
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Illegal start of expression!

    I could just use .25, correct?
    Try it and see what happens.
    If you don't understand my answer, don't ignore it, ask a question.

  12. The Following User Says Thank You to Norm For This Useful Post:

    NoobOfTheMonth (February 11th, 2013)

  13. #10
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Illegal start of expression!

    It got rid of the problem error, and now I just have some more minor stuff that I can take care of, thanks a lot

Similar Threads

  1. Help With illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 9th, 2013, 12:20 PM
  2. need help with illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 9th, 2013, 10:25 AM
  3. Help With illegal start of expression
    By RaceRed in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 7th, 2013, 08:02 PM
  4. PROBLEM: ILLEGAL START OF EXPRESSION
    By zerfgog in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 29th, 2012, 06:24 AM
  5. illegal start of expression error!!!!
    By aks.1393 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 14th, 2011, 07:47 AM