Kelas Mainnya
public class Main{
public static void main(String[]args){
Polindrome p = new Polindrome("kasurrusak");
System.out.println(p.poli());
System.out.println(p.getKata() + " = " + p.poli());
if(p.poli().equals(p.getKata())){
System.out.println("Polindrome!");
}
else{
System.out.println("Tidak Polindrome!");
}
}
}
Kelas Polindromenya
public class Polindrome{
private String kata;
public Polindrome(String input){
this.kata = input;
}
public int getpanjang(){
return this.kata.length();
}
public String poli(){
String poly = "";
for(int i=0; i<getpanjang(); i++){
poly+=this.kata.charAt((getpanjang()-1)-i);
}
return poly;
}
public String getKata(){
return this.kata;
}
}
0 komentar:
Post a Comment