Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Reverse String Method

  1. #1
    Junior Member sweetpee's Avatar
    Join Date
    Oct 2020
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Reverse String Method

    How to add a method to MyStringClass to reverse the string without
    importing the Java string library?

     
    import java.util.Scanner;
     
    class MyStringClass 
    { 
     
       public String getString() {
          // Get console String input
          System.out.print("Enter a String: "); 
          Scanner in = new Scanner(System.in); 
          String str = in.nextLine(); 
          return (str);
       }
     
    }
     
    public class SweetPee {
     
       public static void main(String args[]){
     
          System.out.println("How to add a method to MyStringClass to reverse the string without 
    using Java string library?");
     
          String reverseStr;
     
          // create object instance
          MyStringClass myStrObject = new MyStringClass();
     
          // get string from console
          String str = myStrObject.getString();
          System.out.println("You entered this string: " + str);
     
           // show reversed string from console
          System.out.println("The string reversed is: " + reverseStr);
     
       } 
    }
    Last edited by sweetpee; October 5th, 2020 at 02:06 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Reverse String Method

    Java string library
    Can you explain what that is?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    sweetpee (October 5th, 2020)

Similar Threads

  1. Replies: 9
    Last Post: February 26th, 2013, 11:36 AM
  2. Reverse a String
    By Mehwish-S in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 22nd, 2012, 09:03 AM
  3. Method to take in a string sentence and reverse the tokens
    By ksahakian21 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 25th, 2012, 05:11 PM
  4. [SOLVED] Method to reverse String using While Loop
    By Montrell79 in forum Loops & Control Statements
    Replies: 2
    Last Post: February 22nd, 2012, 03:49 PM
  5. Replies: 3
    Last Post: June 14th, 2009, 09:31 PM

Tags for this Thread