• Post Reply Bookmark Topic Watch Topic
  • New Topic

Print random uppercase letters  RSS feed

 
Kai Jennings
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still doing some Googling/looking around on Oracle, but I'm trying to use the following code to (1) print up to 10 random uppercase letters, and then (2) go back to line 8 where it prints to ask you the input if less than 1 or more than 10 is entered (for the number of random uppercase letters to be displayed)

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kai Jennings wrote:I am still doing some Googling/looking around on Oracle, but I'm trying to use the following code to (1) print up to 10 random uppercase letters, and then (2) go back to line 8 where it prints to ask you the input if less than 1 or more than 10 is entered

Then you'll plainly need some type of loop, so try "Java looping" or "Java loops" or (possibly even better) "Java tutorials loops".

You also haven't said which uppercase letters you want. If it's only English, then why not store a String containing all the letters of the alphabet, and select one of them based on a random number? If you want ANY uppercase letter, then you'll have to box a bit cleverer, but the idea is still the same.

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's always best to break the problem down into simple pieces. some of the things you need to do:

prompt the user
get user input
print a letter/character to the screen
pick a random number
do something a variable number of times (i.e. this is configurable)
validate something is a number
validate a number is less than 10
validate a number is greater than 0

Some of these are trivial. Some may need to be broken down further. the idea is you break a hard, complicated problem into a lot of easy, simple problems. Then you start assembling them like legos.

Don't try and do too much at once. Do a teeny, tiny piece at a time.
 
Raymond Holguin
Ranch Hand
Posts: 82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for (1):

http://www.asciitable.com/

You can just pick a random number between 65 and 90 and get the ASCII value for it.
somethign like this "System.out.println((char)65);", just replace 65 with your random number

for (2)

you can put lines 8 - 16 in a do-while loop and predefine some sort of escape input character to end the process. as long as they keep on type valuees that are not the escape character your process will keep running and print out upper case letters. The condition in the while statement will look for the escape character. of course you will have to add validations to make sure they are typing in valid numbers, etc..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!