snippetjournal

– notes, snippet codes, and my journal

Polindrom JAVA

leave a comment »

Example Polindrom validation


public class Palindrom {

public static void main(String[] args) {
 String pal1 = "TAMAT";
 char[] chars = pal1.toCharArray();
 char[] charsPal = chars.clone();

 int j = 0;
 for(int i = chars.length-1 ; i >= 0; i--){
 if(charsPal[j] == chars[i]){
 System.out.print(" "+charsPal[j]+" ");
 }else{
 System.out.println(" bukan palindrom ");
 break;
 }
 j++;
 }
 System.out.println();
 }
}

package ASN.Coders;

public class PolindromIkhsan {
 public static void main(String[] args) {
 String temp = "";
 String kata = "TAMAT";

 int length = kata.length();
 for(int i = length-1; i >= 0; i--){
 temp = temp+kata.charAt(i);
 }

 if(kata.equals(temp)){
 System.out.println("Polindrom");
 }else{
 System.out.println("Bukan Polindrom");
 }

 }

}

Written by snippetjournal

November 25, 2012 at 1:15 pm

Posted in Programming

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: