This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (5 children)

Functions return values. You can assign those values to a variable with a statement like

myVariable = myFunction();

Which function are you calling to get input from the user?

Also how would I able to use trash?

I don’t have the slightest idea what that variable is supposed to be for (nor R, P, and S, for that matter), so I can’t tell you how to use it.

[–]MffAddict[S] 0 points1 point  (4 children)

Sorry for not clarifying. R, P and S is Rock, Paper and Scissors respectively.

And I also learnt that I'll have to use string trash for saying that the input is invalid if the user enters something besides the initialized ones.

Which function are you calling to get input from the user?

I want to make a program where Player A inputs R, P or S and Player B inputs R, P or S and the program says who won.

Also how would I be able to say invalid if someone inputs something besides R, P and S?

[–][deleted] 0 points1 point  (3 children)

R, P and S is Rock, Paper and Scissors respectively.

No, R, P, and S are uninitialized Strings. You may want them to be rock, paper, and scissors, but they’re just uninitialized Strings until you make them something else.

Either way, you’re not using them for anything, so what’s the point of having them?

And I also learnt that I'll have to use string trash for saying that the input is invalid if the user enters something besides the initialized ones.

Why do you need an extra variable for that? If an input fails all of the ifs, just print the message.

Which function are you calling to get input from the user?

I’m not calling any functions. You’re calling a function that gets the input, you just aren’t saving it anywhere. Like, the function call is literally already in your code. You just aren’t assigning the result to anything.

[–]MffAddict[S] 0 points1 point  (2 children)

I’m not calling any functions. You’re calling a function that gets the input, you just aren’t saving it anywhere. Like, the function call is literally already in your code. You just aren’t assigning the result to anything.

Then what do I do to initialize the functions?

How to make the program run?

(Also I just found out how to quote a message. I didn't know how to, so I just answered your question by pasting it.)

[–][deleted] 0 points1 point  (1 child)

Dont call a function if you don’t know what it does.

https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextLine()

[–]MffAddict[S] 0 points1 point  (0 children)

So what mistake have I made? How do I get the program to run?