First Reverse Solution In Java-Coderbyte


Challenge name: First Reverse

Difficulty: Easy

Maximum Score: 10

Solved language: Java

Description: For this challenge, you will be reversing a string.

Task: Have the function FirstReverse(str) take the str parameter being passed and return the string in reversed order. For example: if the input string is "Hello World and Coders" then your program should return the string sredoC dna dlroW olleH.




Input: "coderbyte"
Output: etybredoc

"I Love Code"
Output: edoC evoL I 


  import java.util.*;

  class Main {

  public static String FirstReverse(String str) {
  // code goes here
  StringBuffer obj =new StringBuffer(str);
  return str;

  public static void main (String[] args) {
  // keep this function call here
  Scanner s = new Scanner(;


Code Explanation:

StringBuffer class: Java StringBuffer class is used to create mutable  String objects. The StringBuffer class in Java is the same as String class except it is mutable.

reverse(): The Java.lang.StringBuffer.reverse() is an inbuilt method which is used to reverse the characters in the StringBuffer.

Post a Comment

* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !