Java :: Aufgabe #106
4 Lösungen

Text in Löffelsprache konvertieren
Anfänger - Java
von Veigar
- 16.12.2015 um 19:05 Uhr
Schreibe ein Script welches einen Text entgegen nimmt und ihn in Löffelsprache konvertiert!
(Löffelsprache: "Geheimsprache" die oft von Kindern benutzt wird, und die dadurch gebildet wird das an jeden Vokal (Selbstlaut) „lew" und dann noch einmal der Vokal gehängt wird. zum Beispiel "Ich bin klug!"-->"Ilewich bilewin klulewug!")
(Löffelsprache: "Geheimsprache" die oft von Kindern benutzt wird, und die dadurch gebildet wird das an jeden Vokal (Selbstlaut) „lew" und dann noch einmal der Vokal gehängt wird. zum Beispiel "Ich bin klug!"-->"Ilewich bilewin klulewug!")
Lösungen:

package de.littlef; import java.util.Scanner; public class Loeffelsprache { private static String sclear; private static String sencoded = ""; private static final char[] toEncrypt = new char[] { 'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U' }; private static final String toAdd = "lew"; private static boolean isVocal; private static Scanner sc; public static void main(String[] args) { // Input sc = new Scanner(System.in); System.out.println("Bitte geben Sie den Text ein:"); sclear = sc.nextLine(); // String durchgehen for (int i = 0; i < sclear.length(); i++) { isVocal = false; // Vokale durchgehen for (int j = 0; j < toEncrypt.length; j++) { // Wenn Vokal dann ändern if (sclear.charAt(i) == toEncrypt[j]) { sencoded += sclear.charAt(i) + toAdd + String.valueOf(sclear.charAt(i)).toLowerCase(); isVocal = true; } } // Wenns kein Vokal war übernehmen if (!isVocal) { sencoded += sclear.charAt(i); } } // Ergebnis ausgeben System.out.println(sencoded); } }

class Loeffelsprache { public static void umwandeln() { String input = "Ich bin klug!"; String lew = "lew"; String akt = ""; for(int i = 0; i < input.length(); i++) { akt = input.substring(i, i + 1); if(akt.equals("a") || akt.equals("e") || akt.equals("i") || akt.equals("o") || akt.equals("u") || akt.equals("A") || akt.equals("E") || akt.equals("I") || akt.equals("O") || akt.equals("U")) { System.out.print(akt + lew + akt.toLowerCase()); } else { System.out.print(akt); } } } public static void main (String[] args) throws java.lang.Exception { umwandeln(); } }
Ich bin noch Anfänger und arbeite mit dem Programm BlueJ
Java-Code

import java.util.Scanner; /** * Umwandeln von Wörtern und Sätzen in die Löffelsprache * * @author (nOrdan aka Nils Jordan) * @version (23.02.2019) */ public class Loeffelsprache { private String text; /** * Konstruktor für Objekte der Klasse Loeffelsprache */ public Loeffelsprache() { } private void textEingabe() { Scanner s = new Scanner(System.in); text = s.nextLine(); } /** * Mit dieser Methode kann man Wörter oder Sätze in die Löffelsprache umwandeln. * Löffelsprache = an jeden Vokal wird ein lew und der jeweilige Vokal angehängt (z.B. Hallo = Halewallolewo) */ public void umwandlung() { System.out.println("Geben sie bitte ihr Wort beziehungsweise ihren Satz ein."); textEingabe(); for (int i = 0; i < text.length(); i++) { //Das If um herauszufiltern ob es ein Vokal ist if (text.charAt(i) == ('A') || text.charAt(i) == ('a') || text.charAt(i) == ('E') || text.charAt(i) == ('e') || text.charAt(i) == ('I') || text.charAt(i) == ('i') || text.charAt(i) == ('O') || text.charAt(i) == ('o')|| text.charAt(i) == ('U') || text.charAt(i) == ('u')) { //Unterscheidung zwischen Groß- und Kleinbuchstaben if (text.charAt(i) == ('A') || text.charAt(i) == ('E') || text.charAt(i) == ('I') || text.charAt(i) == ('O') || text.charAt(i) == ('U')) { //Damit wir bei einem Wort was mit A anfängt nicht ein AlewA sondern ein Alewa stehen haben, da dies nicht der Groß- und Kleinschreibung entsprechen würde. if (text.charAt(i) == ('A')) { System.out.print(text.charAt(i) + "lewa"); } else if (text.charAt(i) == ('E')) { System.out.print(text.charAt(i) + "lewe"); } else if (text.charAt(i) == ('I')) { System.out.print(text.charAt(i) + "lewi"); } else if (text.charAt(i) == ('O')) { System.out.print(text.charAt(i) + "lewo"); } else if (text.charAt(i) == ('U')) { System.out.print(text.charAt(i) + "lewu"); } } //Bei den Kleinbuchstaben muss nur das lew hinzugefügt werden else { System.out.print(text.charAt(i) + "lew" + text.charAt(i)); } } //Alle anderen Buchstaben und Zeichen werden einfach ohne jegliche Veränderung ausgegeben else { System.out.print(text.charAt(i)); } } } }
Löffelsprache, so wie ich sie kenne :D
Java-Code

import java.util.*; public class Loeffelsprache { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("***** Löffelsprache *****"); System.out.print("Bitte einen Satz eingeben: "); String satz = scanner.nextLine(); satz = satz.toLowerCase(); String erg = ""; for(int i = 0; i < satz.length(); i++) { switch(satz.charAt(i)) { case 'a': erg += "alawa"; break; case 'e': if(satz.charAt(i+1) == 'i') { erg += "eileiwei"; i++; } else { erg += "elewe"; } break; case 'i': erg += "iliwi"; break; case 'o': erg += "olowo"; break; case 'u': erg += "uluwu"; break; default: erg += satz.charAt(i); break; } } System.out.println("Ergebnis: " + erg); scanner.close(); } }