Hi I have 3 Strings that I need to be randomly chosen.
HeLlo
hELLo
HElLo
I need a simple code to randomly choose between those three options.
Hi I have 3 Strings that I need to be randomly chosen.
HeLlo
hELLo
HElLo
I need a simple code to randomly choose between those three options.
 
    
     
    
    Make an array of your strings.. Then choose randomly
String[] array = String[]{"HeLlo","hELLo","HElLo"};
    array[(int)(Math.random()*3)]
 
    
    This makes an array of Strings and choses a random index from 0 to 2.
Random r = new Random();
String[] list = {"HeLlo", "hELLo","HElLo"};
System.out.println(list[r.nextInt(3)]);
 
    
    Java Code
import java.util.Random; 
public class TestProgram {
    public static void main(String[] args) {
        String[] myStringArray = {"HeLlo","hELLo","HElLo"};
        Random generator = new Random();
        int randomIndex = generator.nextInt(myStringArray.length);
        System.out.println(myStringArray[randomIndex]);
    }   
}
