Home Tutorial Java Core Java Reverse String Pattern

 
 

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

Related Tags for Java Reverse String Pattern:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.