-
-
Save tobiballof/f3792264de074c51e9da17bc29abbfd5 to your computer and use it in GitHub Desktop.
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 anagramm; | |
import java.util.Scanner; | |
public class Anagramm { | |
public static void main(String[] args) { | |
Helfer helfer = new Helfer(); | |
helfer.suchen(helfer.einlesen("NeuronaleNetze.txt")); | |
} | |
} |
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 anagramm; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
import java.util.StringTokenizer; | |
public class Helfer { | |
//Liest die Datei ein und setzt jedes einzelne Wort in die ArrayList | |
public ArrayList<String> einlesen(String dateiname) { | |
ArrayList<String> e = new ArrayList<>(); | |
Scanner sc; | |
try { | |
sc = new Scanner(new File(dateiname)); | |
while (sc.hasNextLine()) { | |
StringTokenizer str = new StringTokenizer(sc.nextLine(), " "); | |
while (str.hasMoreTokens()) { | |
e.add(str.nextToken()); | |
} | |
} | |
} catch (FileNotFoundException ex) { | |
System.err.println("Datei nicht gefunden!"); | |
} | |
return e; | |
} | |
//Durchsucht die ArrayList nach einen Anagramm zum zuvor eingegebenen Wort | |
public void suchen(ArrayList arrayList) { | |
String str1 = ""; | |
ArrayList<String> array = arrayList; | |
Scanner scan = new Scanner(System.in); | |
System.out.print("Erster String: "); | |
str1 = scan.nextLine(); | |
for (String wort : array) { | |
int length = str1.length(); | |
int counter = 0; | |
if (wort.length() == str1.length()) { | |
for (int i = 0; i < length; i++) { | |
for (int j = 0; j < length; j++) { | |
// String s1 = String.valueOf(wort.charAt(i)); | |
// String s2 = String.valueOf(str1.charAt(i)); | |
/* if (s2.equalsIgnoreCase(s1)) { | |
counter++; | |
} | |
*/ | |
if (wort.charAt(i) == str1.charAt(j)) { | |
counter++; | |
} | |
} | |
} | |
//Das ausgewertete Wort muss gleich lang sein, darf es aber nicht selbst sein | |
if (counter == length && !str1.equalsIgnoreCase(wort)) { | |
System.out.println("Anagramm gefunden! " + wort); | |
} | |
} | |
counter = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment