Skip to content

Instantly share code, notes, and snippets.

@Fundibalus
Created June 6, 2017 12:29
Show Gist options
  • Save Fundibalus/cda516df0b22cdb381bb8ae34654ac60 to your computer and use it in GitHub Desktop.
Save Fundibalus/cda516df0b22cdb381bb8ae34654ac60 to your computer and use it in GitHub Desktop.
/*
* 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;
}
}
/*
* 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;
}
}
/*
* 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