Based on your current implementation i'mI'm going to assume that for strings "ac" and "aaa" we're only removing the first 'a' in both resulting in a draw ("c" and "aa").
Observation 1: The largest of the 2 input strings will always have at least 1 character left after all the removals. This is trivial since we can only remove the number of letters that the smaller string has from the larger one, and by definition it has more letters.
Observation 2: If both strings are of equal length, this will always result in a draw. Either both strings will be emptied completely at the same time, or both will have at least 1 letter left.
So let's use those observations to check as little as possible. First let's write a method that checks if the smallest one will become empty after scrapping all the common letters with the largest one:
private boolean emptyAfterRemovingAll(String smallest, String largest){
List<Character> listLargest = new ArrayList<Character>();
listLargest.addAll(largest.toCharArray());
for(char c : smallest.toCharArray()){
if(!listLargest.remove(c)){
//smallest string contains a character that is not in the largest
return false;
}
}
//able to remove all characters from largest so smallest ends empty.
return true;
}
Now our for main loop becomes something like this:
for(int i=0;i<testcase;i++) {
System.out.println("Enter the 2 strings");
String sa=br.readLine().replaceAll("\\s+", "");
String sb=br.readLine().replaceAll("\\s+", "");
if(sa.length() == sb.length(){
System.out.println("you draw some.");
} else if(sa.length() < sb.length()){
if(emptyAfterRemovingAll(sa,sb)){
System.out.println("You lose some.");
} else {
System.out.println("you draw some.");
}
} else {
if(emptyAfterRemovingAll(sb,sa)){
System.out.println("You win some.");
} else {
System.out.println("you draw some.");
}
}
}