Computer Science, asked by Anonymous, 1 year ago

Write a Java Program to reverse a string without using String inbuilt function.

Answers

Answered by EHSASS
4

                 ஜ۩۞۩ஜ ʜᴇʀᴇ ɪs ʏᴏᴜʀ ᴀɴsᴡᴇʀ ஜ۩۞۩ஜ

Here, we are initializing a string variable str and are making use of the string builder class.

The object of the string builder class str2 will be further used to append the value stored in the string variable str.

Thereafter, we are using the inbuilt function of string builder (reverse()) and storing the new reversed string in str2.

Finally, we are printing str2.

public class FinalReverseWithoutUsingStringMethods {

2

 

3

         public static void main(String[] args) {

4

                  // TODO Auto-generated method stub

5

                  String str = "Automation";

6

                  StringBuilder str2 = new StringBuilder();

7

                  str2.append(str);

8

                  str2 = str2.reverse();     // used string builder to reverse

9

                  System.out.println(str2);

10

         }

11

 

12

}

Output:

noitamotuA

ᴇʜsᴀss   ✿◕ ‿ ◕✿

Answered by Anonymous
1

Java reverse string program: This Java program reverses a string entered by a user. We use charAt method to extract characters from the input string and append them in reverse order to reverse the string. Unfortunately, there is no built in method in String class for string reversal. Fortunately, it is quiet easy to make a method to do it.

Similar questions