Reverse string | Sololearn: Learn to code for FREE!


Reverse string

hello guys, I tried to make a program that reverse a string using pointer but, it does not work when I input a string having please help me to ignore those spaces in my code. I want to reverse a string through pointer not by array. below is my code link:-

3/10/2018 4:12:14 PM

Vivek Mishra

7 Answers

New Answer


you can use getline() function instead of cin to read string with spaces


Just use std::reverse of <algorithm>.


problem solved


//based on Donnas answer import java.util.Scanner; class Rev { public static void main(String[] args) { System.out.print(new StringBuffer(new Scanner(; } }

0 I Hope this thing will help you


import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(; String a = scanner.nextLine(); String b = new StringBuilder(a).reverse().toString(); System.out.println(b); } }


getting an error message after using getline() .will u please modify my code