1
import static javax.swing.JOptionPane.*;

public class ClassPractice {
    public static void main(String args[]) {
        String original, reverse = "";
        original = showInputDialog("Enter a string to reverse");
        int length = original.length();
        int size = length - 1;
        for (int i = size; i >= 0; i--) {
            reverse = reverse + original.charAt(i);
        }
        showMessageDialog(null, "Reverse of entered string is: " + reverse);
    }
}
Maraboc
  • 10,550
  • 3
  • 37
  • 48
  • What's the issue you're running into? It looks like you're currently mirroring it, so `1234` would become `12344321`. Also take a look at [Reverse a string in Java](https://stackoverflow.com/questions/7569335/reverse-a-string-in-java) – phflack Oct 12 '17 at 17:23
  • Possible duplicate of [Reverse a string in Java](https://stackoverflow.com/questions/7569335/reverse-a-string-in-java) – phflack Oct 12 '17 at 17:23
  • I want to flip each and every character of my input string upside down.. The boundaries are that i have have to do it with JOptionPane.. Usage of JFrame or JPanel is restricted. – Xyed Rafa Aly Oct 12 '17 at 17:27
  • Do you have a way to render upsidedown characters? Reversing the string will only work left-to-right, not up-to-down. What does the rest of your code look like? You might be able to reverse the `Graphics` that is rendering the characters – phflack Oct 12 '17 at 17:29
  • I have to dig something out with basic programming skills i.e. loops, arrays, stacks etc. Haven't worked on Graphics yet. – Xyed Rafa Aly Oct 12 '17 at 17:46
  • Give desired inputs and outputs, either as text in a diagram or drawn in something like paint – phflack Oct 12 '17 at 20:26
  • Is it possible to flip a character by help of loop or not ? – Xyed Rafa Aly Oct 15 '17 at 08:56
  • Please explain with a picture or diagram what "flipped is. It's definitely possible, but is a lot more difficult based on what kind of flipped you need – phflack Oct 15 '17 at 10:55

0 Answers0