import java.io.*;
public class soalpalindrom{
static String kata;
static char[] array;
static int top=0;
static char stack[];
public static void main(String[] args) throws Exception{
BufferedReader now = new BufferedReader (new InputStreamReader (System.in));
System.out.println (" ||pengecekkan kata palindrom|| ");
System.out.print("Masukkan kata : ");
kata = now.readLine();
array = kata.toCharArray();
stack = new char[array.length];
for(int i=0; i<array.length; i++){
char a = array[i];
push(a);
}
boolean akhir = true;
for (int i=0; i<array.length; i++){
if (pop() == array[i])
akhir = true;
else akhir = false;
}
if (akhir == true)
System.out.println("Kata "+kata+" adalah Kata Polindrom");
else
System.out.println("Kata "+kata+" Bukan Kata Polindrom");
}
static void push(char a){
stack[top] = a;
top=top+1;
}
static char pop(){
top = top -1;
return stack[top];
}}
Kamis, 11 Desember 2014
Langganan:
Postingan (Atom)