+ 2
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 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
7 Antworten
+ 8
you can use getline() function instead of cin to read string with spaces
+ 3
Just use std::reverse of <algorithm>.
0
problem solved
0
//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());
}
}
0
https://code.sololearn.com/cNeIN0BB018d/?ref=app
I Hope this thing will help you
0
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);
}
}
- 1
getting an error message after using getline() .will u please modify my code