String Question 1

Home / Java Practice Question / String Question 1

String Question 1


Question 1. Write a Program to reverse a String.

Program- 


class Solution {

    public void reverseString(char[] s) {

        int i = 0;

        int j = s.length - 1;        

        while(i <= j){

            char temp = s[i];

            s[i] = s[j];

            s[j] = temp;

            i++;

            j--;

        }

    }

}