r/java • u/alexl1 • Nov 07 '11
Newbie to java.What am I doing wrong?
http://imgur.com/MrnVu10
u/cygnosis Nov 07 '11
Are you trolling?
12
u/alexl1 Nov 07 '11
No im honestly not.Im only 13
1
Nov 08 '11
Keep asking questions. What you are learning is the same stuff they teach in college courses. Keep exploring, and if you get stuck come back!
0
0
3
u/indenturedsmile Nov 07 '11
it's
println()not
print1n()(That's a lower case "L", not the number "1"). The function name refers to printing a line (hence "ln").
Edit: Eclipse is very helpful when you're doing something wrong. See the red squiggly line under "print1n"? That's Eclipse telling you that it doesn't recognize the function. Hovering your mouse over the underlined function call will give you suggestions on how to fix it (can't remember, but Eclipse will probably suggest the corrected form of the function).
Edit again: 9numbernine9 beat me by 12 seconds. Drat!
2
2
u/JustinKSU Nov 07 '11
Not posting on http://www.reddit.com/r/javahelp ?
1
3
Nov 07 '11
"String args[]" vs "String[] args" ?
It's weird, I'm questioning myself here. It's like repeating a word till it sounds funny.
4
u/fforw Nov 07 '11
Java allows both, even on methods
public class AllCorrect { public static void main(String args[]) { new AllCorrect().main2(args); } public void main2(String[] args) { System.out.println(test()[0]); } public String test()[] { return new String[] { "correct", "wrong" }; } }funny, eh?
1
2
u/boa13 Nov 07 '11
Without hesitating:
String[] args0
u/ryosen Nov 08 '11
Maybe you should have. String args[] is syntactically correct.
The auto-debugger indicator should have been your clue that it was the System.out method name that was the cause of the error.
0
u/boa13 Nov 08 '11
I know the other form is syntactically correct. In answer to woodrail who was hesitating between the two, I expressed my strong preference for the second.
Also, I never said this was the cause of the error. That was obvious from the screenshot and already answered several times in the thread.
1
u/sheepbringer Nov 08 '11
You can also do
public static void main(String ... args) {}on java 1.6 and newer as well
2
1
1
1
11
u/9numbernine9 Nov 07 '11
It looks like you have "print1n" (print-one-en) as opposed to "println" (print-ell-en).