Skip to content
Advertisement

(Java) How can I make a loop that will assign random names I’ve generated from an array to multiple strings?

Relatively new to Java, looking for a solution to a crucial part of a game I’m making for a class. The idea is to make a very simple stock market simulation game, but the problem is related to creating made-up company names. I have three arrays for the first, middle, and last names of companies. I’m trying to make some of these companies have one word names, others two, etc. So far I’ve used a random number generator and if/elif/else statement to simulate one, but I would like five of them and I would prefer a more efficient method of doing so. Here’s the code:

JavaScript

Advertisement

Answer

I’d encourage you to play around with it. That’s the fun of programming is solving little puzzles like this, and there are a bunch of ways to do something like this. Here is one to give you some ideas:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement