class, interface or enum expected

class, interface or enum expected error appears when I compile this pr

Page 1 of 1

3 Replies - 1437 Views - Last Post: 23 November 2008 - 10:59 AM Rate Topic: -----

#1 grayzer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-November 08

class, interface or enum expected

Posted 23 November 2008 - 09:47 AM


program class Login
{
	public static void main (string username, string password, int age)
	{

		int length = 0;			// length of the password

		system.out.println( username + ", your password has " + password.length() + " characters.");

		system.out.print1n("Your age is " + age);
	  
		if (age >= 18)
		{
			System.out.printin("You are able to vote in an election")
		}
		else (age <=18)
		{
			Systm.out.println("You are not able to vote );
		}
	  
	}




Is This A Good Question/Topic? 0
  • +

Replies To: class, interface or enum expected

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: class, interface or enum expected

Posted 23 November 2008 - 09:57 AM

Few changes here...

It is not program class Login it is public class Login and you also misspelled System in the line Systm.out.println("You are not able to vote );. You forgot the "e".

You need to close your strings with double quotes as well. You forgot to close it on the end of the line "You are not able to vote".

Don't forget semicolons, you missed one on the end of the line System.out.printin("You are able to vote in an election")

Also remember that Java is case sensitive, so you need to use a capital "S" for system.

Lastly, if you are going to do an else if you have to include the "if part"... else if (age <=18). However in this case if they are not greater than or equal to 18, they have to be less than 18 so you could just use an else...

        if (age >= 18)
        {
            // Notice the capital and the semicolon
            System.out.printin("You are able to vote in an election");
        }
        else
        {
            // It is just an else, no else if needed here. But if you did, it needs the "if" part
            // Notice the closing double quote
            System.out.println("You are not able to vote");
        }



Last but not least, don't forget the closing curly bracket to close off the entire program.

Edit: Gosh you have a lot of errors in this... I forgot to mention that static main has to have the exact signature... public static void main(String[] args) or public static void main(String args[]). You can't pass parameter names to the function. The console parameters will come in through the args array you define.

Hope I got everything. :)

This post has been edited by Martyr2: 23 November 2008 - 10:00 AM

Was This Post Helpful? 0
  • +
  • -

#3 grayzer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-November 08

Re: class, interface or enum expected

Posted 23 November 2008 - 10:26 AM

Thank you very much for your help - i've only being doing this a couple of weeks. I'm a bit unsure about what to put into the first line, i've put the following but it dosen't work?

[code]

public static void main(String args[username, password, int age])

[/code)
I think i'm getting frustrated with it.
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: class, interface or enum expected

Posted 23 November 2008 - 10:59 AM

No as I said it has to be EXACTLY the line public static void main(String[] args). Same words everything. You can't add your own content to the parameters list.

If you wanted to get at the first item passed to the program from the command prompt, you will have to access it using args[0] in your main function body.

The parameters you pass in on the command line are gathered up, put into an array and that array is passed as the "args" array.

:)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1