|
|
Re: help im getting an error
|
Posted: Sep 26, 2008 12:29 AM
|
|
> hello im trying to create an application but it gives me > the errors. how can i correct this? > > public static void main (String args){......} > public class Printstar > { > int x=5; > > while (x > 0) > > { > int y=x; > > while (y > 0) > > { > System.out.print("*"); > y--; > { > System.out.println(" "); > x--; > }}}} > > ERRORS > > C:\Documents and Settings\tole5\My > Documents\Printstar.java:1: class, interface, or enum > expected > public static Void main (String args){......} > ^ > C:\Documents and Settings\tole5\My > Documents\Printstar.java:6: illegal start of type > while (x > 0) > ^ > C:\Documents and Settings\tole5\My > Documents\Printstar.java:6: <identifier> expected > while (x > 0) > ^ > 3 errors > > Tool completed with exit code 1
You're not serious?
take a Java Hello World Tutorial
Your main method should be implemented in a Class.
Methods cannot be declared outside a class Scope.
And your logic has to be placed in a method, i.e. your while loops, printstatements, etc - see myMethod
Also every opening curly bracket needs a closing curly bracket.
Like So:
public class Printstar {
public static void main(String []args) {
// do stuff
}
public void someMethod() {
// place your while statements, etc in here
}
}
Try going through a Java Tutorial and probably try to google on or more of the following: "OO Programming Syntax", "OO Programming".
|
|