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

Thread: Compiling Error on Print method

  1. #1
    Junior Member
    Join Date
    Jul 2020
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Compiling Error on Print method

    I'm creating a program as an exersize which is supposed to take command-line arguments and print out their values.

    Here is my code:

    class InputDataTypes {
    	public static void main(String args[]);
    		Boolean a = Boolean.valueOf(args[0]);
    		Character b = Character.valueOf(args[1]);
    		Byte c = Byte.valueOf(args[2]);
    		Short d = Short.valueOf(args[3]);
    		Integer e = Integer.valueOf(args[4]);
    		Long f = Long.valueOf(args[5]);
    		Float g = Float.valueOf(args[6]);
    		Double h = Double.valueOf(args[7]);
    		System.out.println(a);
    		System.out.println(b);
    		System.out.println(c);
    	}
    }

    These are the error messages I'm receiving:

    InputDataTypes.java:11: error: <identifier> expected
    System.out.println(a);
    ^
    InputDataTypes.java:11: error: <identifier> expected
    System.out.println(a);
    ^
    InputDataTypes.java:12: error: <identifier> expected
    System.out.println(b);
    ^
    InputDataTypes.java:12: error: <identifier> expected
    System.out.println(b);
    ^
    InputDataTypes.java:13: error: <identifier> expected
    System.out.println(c);
    ^
    InputDataTypes.java:13: error: <identifier> expected
    System.out.println(c);
    ^
    InputDataTypes.java:15: error: class, interface, or enum expected

    Every single print method is giving an error. I'm not sure why this is happening.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Compiling Error on Print method

    You need to use {}s with a method to enclose all the statements that are in the method.

    All the statements before the print statements are valid outside of a method.
    The print statements must be defined inside of a method.
    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:

    Nitnatsnok (July 26th, 2020)

  4. #3
    Junior Member
    Join Date
    Jul 2020
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Compiling Error on Print method

    Ah I can't believe I forgot to put the opening bracket after the main method. That's what I get for code late at night.

Similar Threads

  1. Error while compiling.
    By Troy05 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 21st, 2013, 01:16 PM
  2. Compiling error
    By Nithyanathan Naiker in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 7th, 2013, 07:13 AM
  3. Compiling error
    By Bri4n in forum Java Theory & Questions
    Replies: 5
    Last Post: November 7th, 2011, 10:26 PM
  4. Compiling error
    By tangara in forum Java IDEs
    Replies: 3
    Last Post: September 4th, 2011, 03:00 AM
  5. Compiling Error?
    By Arkeshen in forum Java Theory & Questions
    Replies: 2
    Last Post: June 22nd, 2011, 04:31 AM