Syntax error

P

Patrick Vanhoof

Hi,

I am pretty new to Java, and am therefor already blocked by a simple program
(code avalaible below). The last line of the program (the println) gives a
syntax error:
'Syntax error on token "(", "Identifier" expected'
Anyone knows why I get this message?

public class Storage {
Storage st = new Storage();
String str = new String("dit is een string");
public static void main(String[] args) {
}
int storage(String s) {
return s.length() * 2;
}
System.out.println(st.storage(str));
}


Thanks in advance,
Patrick
 
G

Gordon Beaton

'Syntax error on token "(", "Identifier" expected'
Anyone knows why I get this message?

public class Storage {
Storage st = new Storage();
String str = new String("dit is een string");
public static void main(String[] args) {
}
int storage(String s) {
return s.length() * 2;
}
System.out.println(st.storage(str));
}

The last statement doesn't belong to any method (or constructor). Look
at where your braces {} are.

/gordon
 
P

Peter Kirk

Patrick Vanhoof said:
Hi,

I am pretty new to Java, and am therefor already blocked by a simple program
(code avalaible below). The last line of the program (the println) gives a
syntax error:
'Syntax error on token "(", "Identifier" expected'
Anyone knows why I get this message?

public class Storage {
Storage st = new Storage();
String str = new String("dit is een string");
public static void main(String[] args) {
}
int storage(String s) {
return s.length() * 2;
}
System.out.println(st.storage(str));
}

One thing is your println is not in a method.
 
J

Jordan Humber

try this:

public class Storage {

public static void main(String[] args)
{
Storage st = new Storage();
String str = new String("dit is een string");
System.out.println(st.storage(str));
}
int storage(String s)
{
return s.length() * 2;
}

}

HTH,

Jordan.
 
P

Patrick Vanhoof

Thanks, but how do I put it in a method? And how call it then?


Peter Kirk said:
Patrick Vanhoof said:
Hi,

I am pretty new to Java, and am therefor already blocked by a simple program
(code avalaible below). The last line of the program (the println) gives a
syntax error:
'Syntax error on token "(", "Identifier" expected'
Anyone knows why I get this message?

public class Storage {
Storage st = new Storage();
String str = new String("dit is een string");
public static void main(String[] args) {
}
int storage(String s) {
return s.length() * 2;
}
System.out.println(st.storage(str));
}

One thing is your println is not in a method.
 
C

Christophe Vanfleteren

Patrick said:
I am pretty new to Java, and am therefor already blocked by a simple program
(code avalaible below). The last line of the program (the println) gives a
syntax error:
'Syntax error on token "(", "Identifier" expected'
Anyone knows why I get this message?

public class Storage {
Storage st = new Storage();
String str = new String("dit is een string");
public static void main(String[] args) {
}
int storage(String s) {
return s.length() * 2;
}
System.out.println(st.storage(str));
}

One thing is your println is not in a method.
Thanks, but how do I put it in a method? And how call it then?
Please don't toppost.

You put that code in a method the same way you've put return s.length() * 2
inside a method.

Also, please ask these kind of beginner questions in c.l.j.help.
But please read the java tutorial first. These concepts are clearly
explained there:

http://java.sun.com/docs/books/tutorial/java/index.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top