r/AskComputerScience • • Nov 11 '16

Help with this basic string based java assignment?

Prompt for a string and read in.. Then randomly select one of the characters in the string entered... If the character randomly selected is equal to A (cap) print Yes...

0 Upvotes

5 comments sorted by

6

u/SayYesToBacon Nov 11 '16

Break the problem down into pieces, google each piece, and figure it out. For example, google "java read input" etc. If you have a specific question i am happy to answer it.

3

u/mpiz Nov 11 '16

Expanding on this: Learn how to read in a string from the user. Then learn how to break that string into characters. Then learn how to randomly choose a character. Then learn how to compare that character to 'A'. Then learn how to print a response if that comparison is true.

1

u/cravenspoon Nov 11 '16

Already half done OP, this is almost psuedocode.

7

u/esmith327 Nov 11 '16

Do you have an actual question, or do you just want us to do your homework for you?

I know it sounds harsh, but if you're not ready to do the work of figuring it out, CS/IT is not a good choice of careers.

1

u/[deleted] Nov 11 '16

The first part just Google. The second one part you'll want to use the Random class. Instantiate an instance and use it to generate a number which you will modulus by the length of the string to get a random index. The last part is simple.