EVerytime Scrivo qualsiasi codice simile a questo, ottengo questo tipo di errore. Sta costruendo un file ma non permettendogli di farlo funzionare, genera solo un'eccezione. Non ho familiarità con le eccezioni, perché sono un principiante che mi aiuta gentilmente e in particolare mi fa notare l'errore che sto facendo.Eccezione nel thread "main" java.lang.StringIndexOutOfBoundsException: Indice di stringhe fuori intervallo: 11
public static void main(String args[]) {
String name = "Umer Hassan";
String name1 = "Hassan Umer";
char[] name2 = new char[name.length()];
for (int j = 0; j <= name.length(); j++) {
for (int i = 0; i <= name.length(); i++) {
if (name.length() == name1.length()) {
if (name.charAt(i) == name1.charAt(i)) {
name2[i] = name1.charAt(i);
}
}
}
}
}
Quando eseguo il programma che mostra il seguente errore:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 11
at java.lang.String.charAt(String.java:658)
at Anagram.main(Anagram.java:24)
'str.length' dovrebbe essere' str.length() '. – arshajii