Share on Google+Share on Google+

Java Reverse String Pattern

Advertisement
In this section, we have displayed a Java string in reverse pattern.

Java Reverse String Pattern

In this section, we have displayed a string in reverse pattern. For this,we have specified a string which is first converted into character array and then print it. Then we have reversed the string using StringBuffer(st).reverse().toString() and gain convert this string into character array and prnt it also.

Here is the code Java Reverse String: 

class Program1{
public static void main(String[] args) {
    String st="STRING";
    char ch[]=st.toCharArray();
    for(int i=0;i<ch.length;i++){
    System.out.println(ch[i]);
    }
    st = new StringBuffer(st).reverse().toString();
    char ch1[]=st.toCharArray();
    for(int i=1;i<ch1.length;i++){
    System.out.println(ch1[i]);
    }
  }
}

Output :

S
T
R
I
N
G
N
I
R
T
S

Advertisements

Advertisement

Posted on: October 24, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.