Last active
March 21, 2017 17:24
-
-
Save mattiaferigutti/449be43b95e185d61f202e4d48997045 to your computer and use it in GitHub Desktop.
polindroma
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
/** | |
* Created by Mattia on 20/03/2017. | |
*/ | |
public class PolindromaClass | |
{ | |
private String stringa; | |
public PolindromaClass(String stringa) | |
{ | |
this.stringa = stringa; | |
} | |
public void Verifica() | |
{ | |
String s = ""; | |
for (int i=0; i<=stringa.length()-1; i++) | |
{ | |
s = s + stringa.charAt(i); | |
} | |
System.out.println("non polindroma: " + s); | |
String inv = ""; | |
for (int i=stringa.length()-1; i>=0; i--) | |
{ | |
inv = inv + stringa.charAt(i); | |
} | |
System.out.println("polindroma: " + inv); | |
//verifica stringhe | |
if (inv.equals(s)) | |
{ | |
System.out.println("\nsono polindrome"); | |
} | |
else { | |
System.out.println("\nnon sono polindrome"); | |
} | |
} | |
} |
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
public class PolindromaMain | |
{ | |
public static void main(String args[]) | |
{ | |
PolindromaClass pol = new PolindromaClass("tollot"); | |
pol.Verifica(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment