I have created a simple magic 8 ball program. But the issue is every single time I compile my program and run the loop the loop keeps on repeating the same random answer. The issue is not about the loop going on forever its when I compile it and run it, the program gives a random answer but keeps on repeating the same answer till i recompile the file.
import java.util.Random;
import java.util.Scanner;
public class Moreloopex4 {
public Moreloopex4() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
// Declaring Random
Random rand = new Random();
// Declaring scanner
Scanner scan = new Scanner(System. in );
// Declaring variables
String input;
int randnum;
// Declaring randomizer
randnum = rand.nextInt(6) + 0;
// Conditional Statements
while (true) {
System.out.println("Enter your statement");
input = scan.nextLine();
if (randnum == 0) {
System.out.println("Without a doubt ");
}
else if (randnum == 1) {
System.out.println("I cannot predict now");
}
else if (randnum == 2) {
System.out.println("My sources say no");
}
else if (randnum == 3) {
System.out.println("Signs point to yes");
}
else if (randnum == 4) {
System.out.println("Don't count on it");
}
else if (randnum == 5) {
System.out.println("Better not tell you now");
}
else if (randnum == 6) {
System.out.println("Yes, definetly");
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire