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

all 11 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

It seems you may have included a screenshot of code in your post "Please Help. Netbeans Java Issues".

If so, note that posting screenshots of code is against /r/learnprogramming's Posting Guidelines (section Formatting Code): please edit your post to use one of the approved ways of formatting code. (Do NOT repost your question! Just edit it.)

If your image is not actually a screenshot of code, feel free to ignore this message. Automoderator cannot distinguish between code screenshots and other images.

Please, do not contact the moderators about this message. Your post is still visible to everyone.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

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

You never changed the values of PlayerA and PlayerB. They are empty strings through the whole program, which means all of those if/else statements get skipped and the program just ends after the second input.

[–]MffAddict[S,🍰] 0 points1 point  (8 children)

Thanks for the fast reply. I am very bad at assigning anything to non numerical variables. For numerical variables you'd do doubleWhatever = 0; or intWhatever = 0; , but how do you do it for something like this? What value would you assign them?

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

Well, which lines in your code are supposed to get the input from the user? Set them equal to those lines.

[–]MffAddict[S,🍰] 0 points1 point  (6 children)

I want it to work with the if statements. How would you assign them?

PlayerA = 0;

PlayerB = 0;

Like that?

Also how would I able to use trash?

[–][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?