Write a loop that will create a new string that is the reverse of a given string.
________________________________________________________
import javax.swing.JOptionPane;
public class LabExercise16 {
public static void main(String[] args) {
String str = "";
String str2="";
str = JOptionPane.showInputDialog("Enter String: ");
str = str.toLowerCase();
str2 = new StringBuffer(str).reverse().toString();
JOptionPane.showMessageDialog(null, "Original String: "+str+"\nReversed String: "+str2);
}
}
No comments:
Post a Comment