public static void print(String s) {
System.out.println(s);
why s, why s, why s?
could it just as easily have been some other letter? like:
public static void print(String f) {
System.out.println(f);
It is so strange to me that this wasn't explained.
I entered the right solution, but that darn s is throwing me off
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
kvadraats
12 August 2021, 14:09
's' is just a name for it.
Yes, you could easily name it as 'f'.
0
Guadalupe Gagnon
12 August 2021, 14:06
yes. 's' is a variable name and can be named anything that you want it to be, just as long as it follows java's naming rules:
1) must start with a letter
2) must only contain letters(upper and lower), numbers, and some special characters like $ or _
3) can't contain anything else like spaces
4) must not be a word already used by Java (like String, int, var, switch, etc)
So valid names would be things like:
Winter_of_Discontent
R3x
s
f
gr33n$$
while invalid names would be things like:
7rippy (starts with a number)
Winter of Discontent (has spaces)
F#%! (has invalid characters)
goto (goto is a Java keyword)
So you can certainly use 'f' as a variable name. When you are coding on your own it is highly recommended that you use descriptive variable names to make your code easy to read and understand. It is easy and convenient to use single letters names, but it makes it hard for people to understand what your code does... and you could even forget what it does months down the line. There are plenty of memes about this, here are a couple I found hilarious:


+1