-
-
Save laurocaetano/484efcff22b30cbbf03680d3683483dd to your computer and use it in GitHub Desktop.
exercise in Java to delete all vowels in a typed string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() - 1; 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment