Pages

get our extension

Search program

Monday, 29 April 2013

Java Program to Reverse String Without using reverse Function.....


package com.alok;

import java.util.Scanner;

public class String_reverse
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter String :");
String n=sc.nextLine();
String rev="";
int len=n.length();
for(int i=len-1;i>=0;i--)
{
rev=rev+n.charAt(i);
}
                System.out.println("Reverse of Given String is :");
System.out.println(""+rev);
}
}

O/P:- 

Enter String :
ALOK KUMAR
Reverse of Given String is :
RAMUK KOLA


2 comments:

  1. how to reverse without any api. i.e length() and charAt().

    ReplyDelete