Results 1 to 2 of 2
Thread: Magic Eightball
- 11-15-2009, 04:12 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 1
- Rep Power
- 0
Magic Eightball
Hi, guys this is my first java program and i'm having some trouble with a loop. The first question we are supposed to ask is how many questions you would like to ask the eightball and then thats how many times the program is supposed to loop. I can't figure out how to do this for the life of me. Please Help
import java.util.Scanner;
import java.util.Random;
public class scannerinput {
public static void main(String[] args) {
// TODO Auto-generated method stub
Random generator = new Random();
int X = generator.nextInt(20)+1;
int intQuestion;
Scanner SC = new Scanner(System.in);
{
System.out.print("How many questions do you wish to ask?-----");
intQuestion = SC.nextInt();
SC.nextLine();
}
System.out.print("Ask A Yes or No question and you will receive an answer-----");
String Question1 = SC.nextLine();
{
if (X == 1)
System.out.println("As I see it, yes");
if (X == 2)
System.out.println("It is certain");
if (X == 3)
System.out.println("It is decidely so");
if (X == 4)
System.out.println("Most likely");
if (X == 5)
System.out.println("Outlook good");
if (X == 6)
System.out.println("Signs point to yes");
if (X == 7)
System.out.println("Without a doubt");
if (X == 8)
System.out.println("Yes");
if (X == 9)
System.out.println("Yes - definitely");
if (X == 10)
System.out.println("You may rely on it");
if (X == 11)
System.out.println("Reply hazy, try again");
if (X == 12)
System.out.println("Ask again at a later time");
if (X == 13)
System.out.println("Better not tell you now");
if (X ==14)
System.out.println("Cannot predict now");
if (X == 15)
System.out.println("Concentrate and ask again");
if (X == 16)
System.out.println("Don't count on it");
if (X == 17)
System.out.println("My reply is no");
if (X == 18)
System.out.println("My sources say no");
if (X == 19)
System.out.println("Outlook not so good");
if (X == 20)
System.out.println("very doubtful");
}
}
-
The general structure of a for loop is like so:
where "max" above is the total number of times that the for-loop should loop. So simply substitute your int value there:Java Code:for (int i = 0; i < max; i++) { }
Oh and welcome to the forum, and please use code tags. :)Java Code:Scanner input = new Scanner(System.in); System.out.print("How many questions do you wish to ask?-----"); int questionCount = input.nextInt(); input.nextLine(); for (int i = 0; i < questionCount; i++) { // code you want looped goes in here }
Similar Threads
-
Jar files and a magic error.
By dudejonne in forum Java AppletsReplies: 2Last Post: 10-31-2009, 02:28 PM -
[SOLVED] Magic Points Game
By jimmy7 in forum Java AppletsReplies: 6Last Post: 04-26-2009, 11:40 PM -
Problem using buttons to creat a magic square game
By goldman in forum New To JavaReplies: 5Last Post: 05-05-2008, 04:04 AM -
Incompatible magic value 1008821359
By willemjav in forum Java AppletsReplies: 2Last Post: 03-21-2008, 09:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks