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 spaces.so 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:- https://code.sololearn.com/cO91O6NopjBi/?ref=app
3/10/2018 4:12:14 PM
Vivek Mishra7 Answers
New Answer//based on Donnas answer import java.util.Scanner; class Rev { public static void main(String[] args) { System.out.print(new StringBuffer(new Scanner(System.in).nextLine()).reverse()); } }
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String a = scanner.nextLine(); String b = new StringBuilder(a).reverse().toString(); System.out.println(b); } }
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message