Bit of help with this Java script?

3 posts

Flag Post

All I need to do is get the array to output a random colour.

package height_generator;
import java.util.Random;
public class Height_generator {
    Random randomGenerator = new Random();
    int select = randomGenerator.nextInt();
    public static void main(String[] args) {
        String[] aryhair = {"Blue","Red","Black","Blonde"};
        double[] ary1 = {Math.floor(Math.random()*4)};
        double ranheight = Math.floor(Math.random()*9+58);
        System.out.println(ranheight+" Inches Tall");
        System.out.println(aryhair[ary1[0]]);
        }
}

It’s incredibly difficult and I just can’t get it to work.

 
Flag Post
int ary1=randomGenerator.nextInt() % 4;
System.out.println(aryhair[ary1]);

Perhaps this will do.

 
Flag Post

Got it working by reorganizing the code to make it all static, and it ran perfectly.
The new and working code is

package height_generator;
import java.util.Random;
public class Height_generator {

    public static void main(String[] args) {
        Random randomGenerator = new Random();
        int ary1 = randomGenerator.nextInt() % 4;
        int select = randomGenerator.nextInt();
        String[] aryhair = {"Blue","Red","Black","Blonde"};
        double ranheight = Math.floor(Math.random()*9+58);
        System.out.println(ranheight+" Inches Tall");
        System.out.println(aryhair[ary1]);
        }
}

LoL