We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Coz Java's Scanner class understands from where actually 1st digit of double or int begins... For double/int space is not considered as any valid input and so it looks ahead.
But the case is not same for String. Simply enter or space is valid for String. So u need to clear buffer while taking input for String but not the case for int/double.
Java Stdin and Stdout II
You are viewing a single comment's thread. Return to all comments →
Coz Java's Scanner class understands from where actually 1st digit of double or int begins... For double/int space is not considered as any valid input and so it looks ahead. But the case is not same for String. Simply enter or space is valid for String. So u need to clear buffer while taking input for String but not the case for int/double.