ໂຈດ JAVA : word reverse

ໃຫ້ຂຽນໂປຣແກຣມເພື່ອຮັບຄຳສັບເຂົ້າມາ ຫລັງຈາກນັ້ນໃຫ້ປີ້ນຄຳນັ້ນແລ້ວສະແດງອອກທາງມາ ຕົວຢ່າງ : ຖ້າປ້ອນ Ted ຜົນໄດ້ຮັບແມ່ນ deT

ແກ້ໂຈດ :

package Tedev.studio.practice;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        String original;
        String reverse="";
        int len;

        System.out.println("Please enter a word : ");
        original = in.nextLine();
        len = original.length();

        for (int i=len-1; i>=0; i--){
            reverse = reverse + original.charAt(i);
        }

        System.out.println(reverse);
    }
}



Advertisements

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 / ປ່ຽນ )

Twitter picture

You are commenting using your Twitter account. Log Out / ປ່ຽນ )

Facebook photo

You are commenting using your Facebook account. Log Out / ປ່ຽນ )

Google+ photo

You are commenting using your Google+ account. Log Out / ປ່ຽນ )

Connecting to %s