I'm trying to create a system which picks randomly from a list, and then, depending on which string it picked, picks another random string from a seperate group, and then another one from there.
Basically, I'm trying to give it a bunch of paths and then, depending on what choice it makes, narrow the subsequent paths down two more times.
I've got the random code going, but I can't get it to accept if/then/else statements.
Here is my code. It works for its current purpose, which is generating one of those 4 letters randomly. But because it doesn't call a variable, it won't accept if/then/else statements. If I try to make a variable, it complains about being unable to convert the variable to Boolean, but if I define it as Boolean the entire code breaks.
package randomlist;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Randomlist {
public static void main(String[] args) {
// TODO Auto-generated method stub
Random generate = new Random();
String[] name = {"A", "B", "C", "D"};
System.out.println(name[generate.nextInt(4)]);
String nesting =(name[generate.nextInt(4)]);
if (nesting = "A") {
Random generate = new Random();
String[] name = {"E", "F", "G", "H"};
}
else if (nesting = "B") {
Random generate = new Random();
String[] name = {"I", "J", "K", "L"};
}
}
}
Aucun commentaire:
Enregistrer un commentaire