I dont have idea how to show "kim chong" words backward(gnohC mik). anyone have idea for this quenstion pls share thanks!

Dani AI

Generated

asked how to print "kim chong" backwards; and are right to think about reversing the character order. A shorter, idiomatic option in Java is to use the standard library; for full Unicode safety use a code-point aware approach.

Quick one-liner (works well for ASCII and simple text):

String reversed = new StringBuilder("kim chong").reverse().toString();
System.out.println(reversed); // prints "gnohc mik"

For text that may include surrogate pairs (emoji, rare scripts) prefer reversing by code points so pairs are preserved:

String s = "kim chong";
int[] cps = s.codePoints().toArray();
StringBuilder sb = new StringBuilder();
for (int i = cps.length - 1; i >= 0; i--) {
    sb.appendCodePoint(cps[i]);
}
String reversed = sb.toString();

Note: even the code-point approach can split grapheme clusters made of base characters plus combining marks. For true user-visible character reversal look into Java's BreakIterator or ICU4J, and see the standard API docs for StringBuilder and String.codePoints() for details.

Recommended Answers

All 2 Replies

first convert the string to char array and display the elements of that array backwards. There is a method in the String class which converts that string into char array.

JoCamps is correct, as a hint for how to display the array backwards, consider writing a for loop that starts at the ending index of the array and goes backwards, printing out the element at each index.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.