-
-
Save tobiballof/42cd9703df073bbac6961c33a3afeaf1 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package palindrom; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Palindrom { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
Helfer h = new Helfer(); | |
System.out.println("Bitte geben Sie ein Wort ein, von dem Sie denken, dass es ein Anagram ist aber in Wirklichkeit nämlich ein Palindrom ist:"); | |
String text = ""; | |
int length = text.length(); | |
String umgekehrt = ""; | |
ArrayList<String> liste = h.einlesen("NeuronaleNetze.txt"); | |
for (int o = 0; o < liste.size(); o++) { | |
text = liste.get(o); | |
umgekehrt = ""; | |
for (int i = text.length() - 1; i >= 0; i--) { | |
umgekehrt = umgekehrt + text.charAt(i); | |
} | |
if (umgekehrt.equalsIgnoreCase(text)) { | |
System.out.println("Das Wort '" + text + "' ist EIN Palindrom"); | |
} else { | |
System.out.println("Das Wort '" + text + "' ist KEIN Palindrom"); | |
} | |
} | |
} | |
} | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package palindrom; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Helfer { | |
public ArrayList<String> einlesen(String dateiname) { | |
ArrayList<String> e = new ArrayList<>(); | |
Scanner scan; | |
try { | |
scan = new Scanner(new File(dateiname)); | |
while (scan.hasNext()) { | |
String zeile = scan.next(); | |
e.add(zeile); | |
} | |
} catch (FileNotFoundException ex) { | |
Logger.getLogger(Palindrom.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
return e; | |
} | |
} |
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package palindrom; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Helfer { | |
public ArrayList<String> einlesen(String dateiname) { | |
ArrayList<String> e = new ArrayList<>(); | |
Scanner scan; | |
try { | |
scan = new Scanner(new File(dateiname)); | |
while (scan.hasNext()) { | |
String zeile = scan.next(); | |
e.add(zeile); | |
} | |
} catch (FileNotFoundException ex) { | |
Logger.getLogger(Palindrom.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
return e; | |
} | |
} |
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package palindrom; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Palindrom { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
Helfer h = new Helfer(); | |
System.out.println("Bitte geben Sie ein Wort ein, von dem Sie denken, dass es ein Anagram ist aber in Wirklichkeit nämlich ein Palindrom ist:"); | |
String text = ""; | |
int length = text.length(); | |
String umgekehrt = ""; | |
ArrayList<String> liste = h.einlesen("NeuronaleNetze.txt"); | |
for (int o = 0; o < liste.size(); o++) { | |
text = liste.get(o); | |
umgekehrt = ""; | |
for (int i = text.length() - 1; i >= 0; i--) { | |
umgekehrt = umgekehrt + text.charAt(i); | |
} | |
if (umgekehrt.equalsIgnoreCase(text)) { | |
System.out.println("Das Wort '" + text + "' ist EIN Palindrom"); | |
} else { | |
System.out.println("Das Wort '" + text + "' ist KEIN Palindrom"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment