How to Create a Program to Print Reverse of a String Without reverse() method in Core Java

In this tutorial how to create a program to print reverse of a string without reverse() method in Core Java  is shown.

Code:

Reverse.java

import java.io.*;
import java.util.*;

class Reverse
{
public static void main(String args[])
{
String input=args[0];
char[] temparray=input.toCharArray();
int left,right=0;
right=temparray.length-1;
for(left=0;left<right;left++,right–)
{
char temp=temparray[left];
temparray[left]=temparray[right];
temparray[right]=temp;
}
for(char c:temparray)
{
System.out.print(c);
}

}
}

https://youtu.be/wAQ69nCi4jA

Add a Comment

Your email address will not be published. Required fields are marked *