Computer Science, asked by Anonymous, 4 hours ago

write a java program to reverse a string

Answers

Answered by BrainlyProgrammer
6

Answer:

import java.util.*;

class abc{

public static void main (String ar []){

Scanner sc=new Scanner(System.in);

String s =sc.nextLine();

for(int I=s.length()-1;I>=0;I--)

System.out.print(s.charAt(I));

}

}

  • Run a reverse loop and print thr character at that position
Attachments:
Answered by Oreki
5

\textbf{\large Reversing a String in Java}

     \textsf{\textbf{Using the Library classes}}

           \texttt{StringBuilder sb = new StringBuilder("String-to-be-reversed");}\\\texttt{sb.reverse();}\\\texttt{System.out.println("Reversed String - " + sb.toString());}\begin{center} \textsf{\textbf{or,}} \end{center}

           \textsf{// A short method for convivence}\\\texttt{String reverse(String word) \{}\\\texttt{\hspace{1.5em} return new StringBuilder(word).reverse().toString();}\\\texttt{\}}

\textbf{Similar Questions}

   https://brainly.in/question/<number>

   37937856, 33815868, 9121483, 21530589 and 13379846.

Similar questions