Skip to content

Instantly share code, notes, and snippets.

@princessofpain
Last active September 26, 2017 09:22
Show Gist options
  • Save princessofpain/0eecf5eb1987bcafbf30d03a8f20b093 to your computer and use it in GitHub Desktop.
Save princessofpain/0eecf5eb1987bcafbf30d03a8f20b093 to your computer and use it in GitHub Desktop.
exercise in Java to delete all vowels in a typed string
package uebung07;
import javax.swing.JOptionPane;
public class Vokalloescher {
static String eingabe = JOptionPane.showInputDialog("Geben Sie einen Text ein:");
static String klein = eingabe.toLowerCase();
public static boolean istEinVokal(char ch){
switch(ch){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': return true;
} return false;
}
public static String loescheVokale() {
StringBuilder oVokale = new StringBuilder(klein);
for (int i = 0; i <= oVokale.length(); i++) {
if (istEinVokal(oVokale.charAt(i))) {
oVokale.deleteCharAt(i);
}
}
return oVokale.toString();
}
public static void main(String[] args) {
System.out.println(klein);
System.out.println(loescheVokale());
JOptionPane.showMessageDialog(null, klein);
}
}
alle katzen sind grau
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 15
at java.lang.AbstractStringBuilder.charAt(AbstractStringBuilder.java:237)
at java.lang.StringBuilder.charAt(StringBuilder.java:76)
at uebung07.Vokalloescher.loescheVokale(Vokalloescher.java:22)
at uebung07.Vokalloescher.main(Vokalloescher.java:31)
Process finished with exit code 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment