How to reverse String using java - learn java

in #programming7 years ago

hello steemit community,

This is Ravi here

kkmk.jpg

I know there is the various person who not interested with programming.

if some people like programming and love with code for those i write a program to reverse a string using java technology.

Program:

class Reversestring
{
public static void main(String args[])
{
String s="ravikumar";
char ch[] = s.toCharArray();
for(int i=s.length()-1;i>=0;i--)
{
System.out.print(ch[i]);
}
}
}

Hope you like it...

don't forget to follow me

by @ravik2492

ravik2492 level.png

Sort:  

Cool idea -- this is a super common interview question. Here's my own implementation in Python.

def reverse_string(string): 
    length = len(string)
    new_string = "" 
    for i in range(length): 
        new_string = new_string + string[length-i-1]
    return new_string

ravik best work follow me to help each other comment and vote

You can do it without the character array:

class Reversestring
{
  public static void main(String args[])
  {
    String s="ravikumar";
    for(int i=s.length()-1;i>=0;i--)
    {
      System.out.print(s.charAt(i));
    }
  }
}

Would be nice to see it as OOP based class static and not static :)

Congratulations @ravik2492! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!