Home Java Overview Maven Tutorials

Friday, 22 December 2017

reverse the string in java without using functions

For Video :- Click Here

Hello friends,

In this article we will learn Reverse a String with and without using Java Functions :-

import java.util.Scanner;
public class Stringplay
public static void main(String args[])
String rev = "";
Scanner sc = new Scanner(;
System.out.println("Enter your first string");
String ys = sc.nextLine();
int length = ys.length();
for(int i =length-1; i>=0; i--)
rev = rev + ys.charAt(i);
System.out.println("Your String is: " +ys);
System.out.println("reverse String is: " +rev);
StringBuffer sb = new StringBuffer(ys);
rev = sb.reverse().toString();
System.out.println("simple reverse String is: " +rev);

And here is your output:

Enter your first string
chandan singh
Your String is: chandan singh
reverse String is: hgnis nadnahc
simple reverse String is: hgnis nadnahc

No comments:

Post a Comment