Right now I'm trying to make a program to take user input and have the program take in five names and select three names. At the moment I have it taking in the five names and giving the input each a value to one of the subvalues of the array but I don't know how to randomly select three names because the random function only works with integers. Below is what I have so far (after I get this solved I will simplify the input portion with a nested loop lmao:
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.util.Random;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] names = new String[5];
Random selecter = new Random();
names[0] = JOptionPane.showInputDialog("Please enter a name (1/5): ");
names[1] = JOptionPane.showInputDialog("Please enter a name (2/5): ");
names[2] = JOptionPane.showInputDialog("Please enter a name (3/5): ");
names[3] = JOptionPane.showInputDialog("Please enter a name (4/5): ");
names[4] = JOptionPane.showInputDialog("Please enter a name (5/5): ");
}
}
