Home Tutorial Java Core Java Reverse String Pattern

 
 

Share on Google+Share on Google+
Java Reverse String Pattern
Posted on: October 24, 2009 at 12:00 AM
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
Advertisement

Related Tags for Java Reverse String Pattern:


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.

Posted on: October 24, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com