Ask Question
27 September, 19:09

Write a "for loop" that displays a string in the reverse order (DO NOT use the reverse method) 3.

+5
Answers (1)
  1. 27 September, 21:13
    0
    Following are the code in java to reverse any string without using reverse function.

    import java. util.*; / / import package

    class Main / / class

    {

    public static void main (String args[]) / / main class in java

    {

    String s, r = ""; / / string variable

    Scanner out = new Scanner (System. in); / / scanner classes to take input

    System. out. println ("Enter a string to reverse");

    s = out. nextLine (); / / input string

    int l1 = s. length (); / / finding length of string

    l1=l1-1;

    for (int i = l1; i > = 0; i--) / / for loop to reverse any string

    {

    r = r + s. charAt (i);

    }

    System. out. println (" The Reverse String is: "+r); / / print reverse string

    }

    }

    Explanation:

    firstly we input any string, finding the length of that string then after that iterating over the loop by using for loop and last display that reverse string

    output

    Enter a string to reverse

    san ran

    The Reverse String is: nar nas
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a "for loop" that displays a string in the reverse order (DO NOT use the reverse method) 3. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers