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 5 of 5

Thread: Help With illegal start of expression

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help With illegal start of expression

    I have gotten many errors on my "public classes" saying illegal start to expressions and semicolons. Am i missing a bracket somewhere or is it something else.

        //java packages
    	import java.util.Scanner;
     
     
        public class PiggyRunner
    		{ //start PiggyRunner
    	public static void main (String[] args)
     
    	{ //start main
     
     	Scanner keyboard = new Scanner (System.in);
     
        //Variables Set Data
    	 double total;
    	 private int pennies;
    	 private int nickels;
    	 private int dimes;
    	 private int quarters;
    	 private int halfdollars;
    	 String cont = "";
     
     
    	public Piggy() //constructor
    	{ //start CalculatorAmounts
    	 total = 0.0;
    	 pennies = 0;
    	 nickels = 0;
    	 dimes = 0;
    	 quarters = 0;
    	 halfdollars = 0;
       } //end CalculatorAmounts
     
     
    	public void Piggy(double tot, int pens, int niks, int dim, int quart, int hfdoll)
         { //SetData
    	 pennies = pens;
    	 nickels = niks;
    	 dimes = dim;
    	 quarters = quart;
    	 halfdollars = hfdoll;
    	  } //SetData
     
     
     
    	public void calculatePiggy()
      { // begin calculatePiggy
        total = (.01*pennies);
    	total = (.05*nickels);
    	total = (.10*dimes);
    	total = (.25*quarters);
    	total = (.50*halfdollars);
      } // end calculatePiggy
     
     
    	public void printValue()
    	{//start PrintWealth
      System.out.printf (" Your total value of pennies is %.2f \n",
      pens );
      System.out.printf("");
      System.out.printf (" Your total value of nickels is %.2f \n",
      niks );
      System.out.printf("");
      System.out.printf (" Your total value of dimes is %.2f \n",
      dim );
      System.out.printf("");
      System.out.printf (" Your total value of quarters is %.2f \n",
      quart );
      System.out.printf("");
      System.out.printf (" Your total value of halfdollars is %.2f \n",
      hfdoll );
      System.out.printf("");
     }//end PrintWealth
    	if ( total<5 )
    	{ //begin if tot<5
    	   System.out.println("HA HA HA HA I know who isn't going anywhere soon!");
    	} //end if tot<5
     
    	if ( total>5 && total<15 )
    	{ //begin if tot>5 && tot<15
       		System.out.println("You got enough for a movie ticket!");
    	} //end if tot>5 && tot<15
     
    	if ( total>15 && total<25 )
    	{ //begin if tot>15 && tot<25
    	    System.out.println("Thats what happens when you save your pennies!");
    	} //end if tot>15 && tot<25
     
    	if ( total>25 )
    	{ //begin if tot>25
    	   System.out.println("Make it Rain!!!");
    	} //end if tot>25
     
     
     
     
     
    	}//end main
     
    	}//end PiggyRunner


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With illegal start of expression

    Could be mismatched {}s
    If the } //end main is supposed to end the main() method, then there is a problem with defining methods inside of methods which can't be done.

    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.

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

    RaceRed (February 7th, 2013)

  4. #3
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Help With illegal start of expression

    I think you may be nesting the constructor inside the main() method which makes no sense. The compiler will grumble when it hits the "public" of the constructor. That and mismatched braces are a common source of "illegal start of expression" messages.

    When you post code, use the "code" tags - put [code] at the start of the code and [/code] at the end. This will allow the formatting to be visible in the post.

  5. The Following User Says Thank You to pbrockway2 For This Useful Post:

    RaceRed (February 7th, 2013)

  6. #4
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With illegal start of expression

    Thank you for your responses, but im having trouble understanding i should put my main in front of my piggyrunner bracket

  7. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help With illegal start of expression

    The ending } for the main() method should be before any other method definitions.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need HELP! Illegal start of expression & while expected..
    By Zaki in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 15th, 2012, 04:22 PM
  2. 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
  3. illegal start of expression error!!!!
    By aks.1393 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 14th, 2011, 08:47 AM
  4. Illegal Start of Expression Error. Any help is appreciated.
    By SKhoujinian91 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 8th, 2009, 12:57 AM