Biyernes, Setyembre 20, 2013

LabExer#15

16. Write a loop that will create a new string that is the reverse of a given string.




import java.util.*;

import javax.swing.JOptionPane;

public class ReversedString {
    public static void main(String[] args) {
        String str;
        Scanner input=new Scanner(System.in);
   
        str=JOptionPane.showInputDialog("Enter String: ");
        str=str.toLowerCase();
       
        String reverse="";
       
        for(int x=str.length()-1;x>=0;x--){   
            reverse=reverse+str.charAt(x);
        }       
        System.out.println("Original string: "+str);
        System.out.println("Reversed string: "+reverse);
    }
}   
               
   

Walang komento:

Mag-post ng isang Komento