I'm having trouble with my program. I need to enter only capital letters, R,B,W. Validate the correct input and then sort the string. Output should be sorted with R's first, B's second and W's third. I can only get the alphabetized output, not the needed output. I don't know what to do next.
System.out.print("Enter a string of capital letters made up of R, B, W: ");
Scanner s = new Scanner(System.in);
String letters;
for (letters = s.nextLine(); !letters.matches("[RBW]+"); letters = s.nextLine())
{
System.out.println("Invalid entry. Please enter the correct letters.");
}
System.out.println("Thank you");
char[] sort2 = letters.toCharArray();
Arrays.sort(sort2);
String sorted = new String(sort2);
System.out.println("Here are your letters sorted:" +sorted);