Random in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Random in Java

How can i randomize string variables in java and would want to use random with JOptionPane. For example I want the user to give their name using JOptionPane then their name will be allocated to a color and the colors must be randomly selected.

19th May 2019, 4:04 PM
Augustine Madimutsa
Augustine Madimutsa - avatar
2 Answers
+ 2
Here are three ways to create a random number: https://www.google.de/amp/s/www.geeksforgeeks.org/generating-random-numbers-in-java/amp/ If your color is in a list or array, you could create a random number between 0 and length of list/array for the index.
19th May 2019, 4:52 PM
Denise Roßberg
Denise Roßberg - avatar