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
I have done a few changes in your code, it will run just fine for this code
package practise;
import java.util.Scanner;
public class scanccls {
public static void main(String[] args) {
//// TODO Auto-generated method stub
System.out.println("Enter your name:");
Scanner scan = new Scanner(System.in);
String name="";
name+=scan.nextLine();
scan.close();
System.out.println("Your name is :"+name);
}
}