Okay, Now I am able to parse space which was my previous problem. Now my parser is almost ready but has a defect which I am unable to figure out.
I am able to retrieve D
Scanner() by default has space as delimeter. So if you do scanner.next() again then you will get the remaining input part, '4'.
You can set your own delimeter by using usedelimeter(String pattern) api of Scanner class.
usedelimeter(String pattern)