I am trying to create a population of chromosomes in which an individual chromosome consist of an array of char characters. Each character in the array is unique and is obtained from the user. Below is my main class;
public class Main {
static String rawData;
static char [] charArray;
public static void main(String[]args) {
Scanner user_input = new Scanner(System.in);
System.out.print("Please enter your message here.\n");
rawData = user_input.nextLine();
}
}
and my individual chromosome(array) looks like this;
public class Individual extends Main {
void CreateIndiv() {
charArray = rawData.toCharArray();
for (int i=0; i<charArray.length; i++) {
for (int j=i+1; j<charArray.length; j++) {
if (charArray[i] == charArray[j]) {
charArray[i] = 0;
}
}
}
for (int i=0; i<charArray.length; i++) {
if (charArray[i] != 0) {
System.out.print(charArray[i]);
}
}
}
}
Could any one assist me to create random population (arrays) from this individual char array. Please correct me if I am using the wrong code to create an individual.