Magic 8 ball

import java.util.*; public class MagicBall { String[] responses = {"I would be suprised", "My visions say Yes", "Of course not", "Maybe", "Nope", "Probably", "Are you dumb?"}; boolean again = true; public MagicBall() { while(again = true){ System.out.println("Enter Your Question (Press X to Exit)."); Scanner sc = new Scanner(System.in); String question = sc.next(); if(question.equals("X")) break; int answer = (int)(Math.random() * 7); String theresponse = responses[answer]; System.out.println(theresponse); } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.