The Student Room Group

Need help writing simple java method

I need to write a method that returns the String “Hello World!”
using this prototype function:
public static String HelloWorld()

Any help pls?
is this homework? do you have the full context?
i could very easily write out the answer but there's no point in spoonfeeding since it doesn't help
Reply 2
Yes this is just the first bit All the questions have a similar layout but if you can show me the first one i'll be able to understand how its done. The bit that is confusing me is using the prototype function
https://hastebin.com/amaxuzohof.cpp
This creates a new variable, stores "Hello World!" in it, and then it returns this variable.
Reply 4
Ah ok looks good appreciate it.
it's bad practice to do that,

return "Hello World";

is better. Declaring variables in functions just to return them straight away makes code hard to read for no reason.

Quick Reply

Latest

Trending

Trending