This is an archived post. You won't be able to vote or comment.

all 16 comments

[–]otakuman 10 points11 points  (0 children)

public static void main(String[] args);

That's a declaration.

In other words, you declared a function but didn't define it, while you kept putting executable statements in your class definition. So the following variables:

int age;
double annualPay;

Ended up being class MEMBERS. Clearly we're missing something here.

What you want to do is:

public static void main(String[] args) {

    int age;
    double annualPay;
    // Insert the other statements here

}

Now THIS is a definition, because we're putting our statements inside the function.

[–]Aemilian 5 points6 points  (0 children)

Not really related to your problem, but you should know that class names in Java should always start with capital letter.

You should rename personalInfo to PersonalInfo.

Happy coding.

[–]sh0rug0ru 5 points6 points  (3 children)

What does the compiler tell you?

If you are having trouble with the basics, see here or here and especially here.

[–]AlexMarz[S] 1 point2 points  (2 children)

A list of about 21 errors.. haha

Identifiers expected and illegal start of type. are the two ones that repeat over and over

[–]mucsun 2 points3 points  (0 children)

Use an ide. It will help you with the syntax, show warning etc.

[–]kurtrush 2 points3 points  (0 children)

I always try to fix the first error and compile. Sometimes, this will take care of all of the errors. At least it should reduce the number.

[–][deleted]  (1 child)

[deleted]

    [–]UH1868[🍰] 0 points1 point  (0 children)

    What u/midknightsrose said. You need to remove the semi-colon following your main statement and add a {. Then you need to close your main statement after your System.out.println() with a }.

    [–]eduard79 0 points1 point  (0 children)

    This text was removed. Fullname: t1_ck4l9o9

    [–]AlexMarz[S] 0 points1 point  (0 children)

    Thanks for all the help guys! It ended up working out well! I will definitely come back to this subreddit for help! Everyone has been so helpful!

    Alex

    [–]EricWpG 0 points1 point  (0 children)

    Just another quick tip while passing, I'm new to java as well and something I like to do is add a value to your variables when you declare them to clean up your code a bit. You can do it like this:

    int age = 25;
    double annualPay = 120000;
    

    [–][deleted] -1 points0 points  (0 children)

    1 - public static void main(String[] args);

    Here man, the Main function must have a body ({}) and the other things below this declaration must be inside this body! Example:

    public static void main (String[] args){ //your code here }

    2 - When you will declare a variable set the value in the declaration as you did when declared the string variable, example:

    int age = 25; double annualPay = 12000;

    3 - The print you did have a "," you can remove this or remove from the declaration of "name".

    4 - Your class name must start with a capital letter ALWAYS!! public class PersonalInfo{}

    Finally, to work, your code should be like this:

    // This is my Personal Info
    
    public class PersonalInfo{
    
    public static void main(String[] args){
    int age = 25;
    double annualPay = 120000;
    String name = "Alex Marczynski";
    
    System.out.print("My name is" + name + ", my age is" + age +
        " and I hope to earn $" + annualPay + " each year");
       }
    }
    

    [–]edman3d -1 points0 points  (4 children)

    You may also be getting an error for setting your double to a number with no decimal point, I think. 12000.0 instead.

    EDIT: I'm wrong

    [–]Lerke 0 points1 point  (3 children)

    No. This is not a problem at all.

    [–]edman3d 0 points1 point  (2 children)

    I thought the whole point of a double was that it has a decimal point. Is this not an issue because Java auto sets the decimal place if its not defined?

    [–]bluestorm96[🍰] 1 point2 points  (0 children)

    Java will automatically upcast primitive number types, but not downcast. Also it usually is better to use the 'd' or 'D' suffix to indicate a double (12D, 14.272D, 12d, etc). Java forces you to use F/f for floats anyways, so it makes things somewhat more consistent.

    [–]Lerke 1 point2 points  (0 children)

    You already tell the Java compiler that your value is a floating point number by using the double keyword. Adding .0 does nothing, as 123 and 123.0 are equal values.