Java Scanner class not reading correctly after nextInt() or nextDouble method call

Scanner is a utility class that provides methods to read command-line input. It is a very useful class, but you need to be aware of its unexpected behavior while reading numeric inputs. Consider following example.