Magic 8 ball Download

Christina Cacioppo

random, arrays Student approved


Ever play with a Magic 8 ball? And get really frustrated when it kept telling you to "ask again later"?

When you make your own Magic 8 Ball – which we're about to do! – you get to write the answers.


Below is the start of a Magic 8 Ball program, though it doesn't work yet.

Change it by:

  1. Ask the Magic8Ball a question by storing a string in the question variable.
  2. Adding at least five answers your 8 Ball could give to the String[] answers. Remember to format each as a string. If you'd like your Magic 8 ball to have more than five potential answers, just increase the array's size.
  3. Pull out a random String from String[] answers to be the Magic 8 Ball's answer.
  4. Print the randomly-chosen answer.

Happy fortune telling!

Starter code

import java.util.Random;

class Magic8{
	public static void main(String[] args){
		String question = "Your question here";

		// Fill the array with at least five potential answers
		String[] answers = new String[5];

		// Choose one of the answers at random, then print it

Expected output

Will I be a great computer scientist?
But of course!

One solution


Useful tools to solve the problem

Related links