Pilih Elemen dari Array di Java
import java.util.*;
public class arrayElement {
public static void main(String[] args) {
int[] forInts = { 1, 2, 3, 4, 5 };
System.out.println(forInts[0]); // Prints 1
String[] forStrings = { "hello", "hi", "how do you do" };
System.out.println(forStrings[0]); // Prints "hello"
// RANDOM ELEMENT PICK
Random r = new Random();
int pick = r.nextInt(forInts.length);
System.out.println(forInts[pick]); // Picks random int and prints it
int pick2 = r.nextInt(forStrings.length);
System.out.println(forStrings[pick2]); // Picks random string and prints it
}
}