Hey,
erkennt jemand von euch, was das Problem mit meinem Code ist? NetBeans liefert mir folgende exception:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at letterinvert.LetterInvert.main(LetterInvert.java:29)
[Java]public class LetterInvert {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String [] s = new String[10];
s[0] = "H";
s[1] = "a";
s[2] = "l";
s[3] = "l";
s[4] = "l";
s[5] = "o";
s[6] = " ";
s[7] = "W";
s[8] = "e";
s[9] = "l";
s[10] = "t";
String [] lowerCase = new String[7];
lowerCase[0] ="h";
lowerCase[1] = "a";
lowerCase[2] = "l";
lowerCase[3] = "o";
lowerCase[4] = "w";
lowerCase[5] = "e";
lowerCase[6] = "l";
lowerCase[7] = "t";
String [] upperCase = new String[7];
upperCase[0] ="H";
upperCase[1] = "A";
upperCase[2] = "L";
upperCase[3] = "O";
upperCase[4] = "W";
upperCase[5] = "E";
upperCase[6] = "L";
upperCase[7] = "T";
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (s.equals(lowerCase[j])) {
System.out.print(upperCase[j]);}
if (s.equals(upperCase[j])){System.out.print(lowerCase[j]);}}}
}
}[/Java]
erkennt jemand von euch, was das Problem mit meinem Code ist? NetBeans liefert mir folgende exception:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at letterinvert.LetterInvert.main(LetterInvert.java:29)
[Java]public class LetterInvert {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String [] s = new String[10];
s[0] = "H";
s[1] = "a";
s[2] = "l";
s[3] = "l";
s[4] = "l";
s[5] = "o";
s[6] = " ";
s[7] = "W";
s[8] = "e";
s[9] = "l";
s[10] = "t";
String [] lowerCase = new String[7];
lowerCase[0] ="h";
lowerCase[1] = "a";
lowerCase[2] = "l";
lowerCase[3] = "o";
lowerCase[4] = "w";
lowerCase[5] = "e";
lowerCase[6] = "l";
lowerCase[7] = "t";
String [] upperCase = new String[7];
upperCase[0] ="H";
upperCase[1] = "A";
upperCase[2] = "L";
upperCase[3] = "O";
upperCase[4] = "W";
upperCase[5] = "E";
upperCase[6] = "L";
upperCase[7] = "T";
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (s.equals(lowerCase[j])) {
System.out.print(upperCase[j]);}
if (s.equals(upperCase[j])){System.out.print(lowerCase[j]);}}}
}
}[/Java]
Zuletzt bearbeitet von einem Moderator: