Java Reverse String Pattern


 

Java Reverse String Pattern

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

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

Ads