The Artima Developer Community
Sponsored Link

Java Answers Forum
help im getting an error

4 replies on 1 page. Most recent reply: Dec 12, 2008 1:42 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
tony le

Posts: 1
Nickname: aznb0i7688
Registered: Sep, 2008

help im getting an error Posted: Sep 25, 2008 9:47 AM
Reply to this message Reply
Advertisement
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


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: help im getting an error Posted: Sep 26, 2008 12:29 AM
Reply to this message Reply
> 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".

karan khusahl

Posts: 1
Nickname: karan123
Registered: Oct, 2008

Re: help im getting an error Posted: Oct 19, 2008 3:00 AM
Reply to this message Reply
Here is the working program
try this out.

public class Printstar
{
public static void main(String... ar)
{
int x=5;
while (x > 0)
{
int y=x;

while (y > 0)
{
System.out.print("*");
y--;
}
System.out.println(" ");
x--;
}
}
}

nastik bautista

Posts: 4
Nickname: nastik
Registered: Dec, 2008

help me please.. Posted: Dec 10, 2008 6:26 AM
Reply to this message Reply
i bought a book.. JAVA PROGRAMING D.S. MALIK, can you please tell me where can i get some answers on the book? my professor said that there is a site or forum which can help me answer some of the questions. thanks

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: help me please.. Posted: Dec 12, 2008 1:42 AM
Reply to this message Reply
readthe introduction.
a class does not contain code, only methods contain code.
a class is a container for class variables and containers

The hello world tutorial should show you where to put your working code.

Flat View: This topic has 4 replies on 1 page
Topic: Help for the socket.... Previous Topic   Next Topic Topic: please ...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use