I am a beginner to java. I developed a Java code to compare whether two user input Strings contain similar characters at equal frequencies and print them to the screen. But it shows a run time error ( ArrayOutOfBoundException ) during the compilation process. Help me to find the error.
import java.util.Scanner;
public class Checker {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String x = scan.next();
String y = scan.next();
boolean anws = similarCharctr(x, y);
System.out.println( (anws) ? "Similar" : "Dissimilar" );
}
static boolean similarCharctr(String x, String y) {
boolean status = false;
if(x.length() == y.length()){
status = false;
}
String e = x.toUpperCase();
String f = y.toUpperCase();
char c [] = new char[e.length()];
char d [] = new char[f.length()];
for(int i = 0; i<c.length; i++){
c[i] = e.charAt(i);
d[i] = f.charAt(i);
}
for(int j = 0; j< (c.length - 1); j++){
for(int i = 0; i< c.length; i++){
if( c[j] >c[i+1])
{
char temp;
temp = c[j];
c[j] = c[i+1];
c[i+1] = temp;
char temp1;
temp1 = d[j];
d[j] = d[i+1];
d[i+1] = temp1;
}
}
}
for(int i = 0; i< c.length; i++){
if(c[i] == d[i]){
status = true;
}
else{
status = false;
}
}
return status;
}
}