Home » , » Membaca Kalimat Terbalik Pada Java (String Reverse)

Membaca Kalimat Terbalik Pada Java (String Reverse)

Posted by Tutorial Programming on Rabu, 10 Oktober 2012


# Ok langsung saja kalian coba dan analisa program dibawah ini :


public class BacaTerbalik{
    public static void main(String[] args) {
        String first, middle, tamp[];
        char dumy[];
        first = "Malang Kota Bunga";
        System.out.println("Pertama >> " + first);
        middle = new StringBuffer(first).reverse().toString().toLowerCase();
        dumy = middle.toCharArray();
        for (int i = 0; i < dumy.length; i++) {
            if (i == 0) {
                char c = dumy[i];
                dumy[i] = Character.toUpperCase(c);
            } else {
                if (dumy[i] == ' ') {
                    char c = dumy[i + 1];
                    dumy[i + 1] = Character.toUpperCase(c);
                }
            }
        }
        middle = String.valueOf(dumy);
        System.out.println("Proses1 >> " + middle);
        tamp = middle.split(" ");
        System.out.println("Proses2 >> " + tamp[2] + " " + tamp[1] + " " + tamp[0]);
        tamp = first.split(" ");
        System.out.println("Proses3 >> " + tamp[2] + "" + tamp[1] + "" + tamp[0]);
    }
}

loading...

0 comments:

Posting Komentar

Popular Posts