I need to read spaces (present before string and after String) given as input using Scanner Note : if there is no spaces given in input it should not add space in output
One can use the delimiter function to segregate your input as shown below.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in).useDelimiter("\n");
String input = scanner.next();
System.out.println(input);
scanner.close();
}
}