java


Scanner not asking input of string


In the below code:
secondI = scan.nextInt();
System.out.println("double");
secondD = scan.nextDouble();
System.out.println("string");
secondS = scan.nextLine();
After entering the double value, it is skipping the string entry part. How can I fix this?
secondI = scan.nextInt();
System.out.println("double");
secondD = scan.nextDouble();
scan.nextLine();
System.out.println("string");
secondS = scan.nextLine();
You need to have this extra nextline statement which consumes the remaining section of that line which you entered for the double value.
Use
secondS = scan.next();
instead of
secondS = scan.nextLine();
Please see the documentation for Scanner.nextLine().
Advances this scanner past the current line and returns the input that was skipped.
Try using other methods of the Scanner class such as Scanner.next()

Related Links

instance method reference. no suitable method found for
Tomcat 7.0 HTTP post request utf-8 issues with windows server 2008 R2
Is there a BiMap implementation with predictable iteration ordering (insertion order)?
Eclipse says “Constructor is undefined”
AlarmManager can't be cancelled in the Activity
Login to PHP based website via Java Application
JButton does not return the right text value
Regex to extract numbers and group them with thousands separator
Properly use the RelationshipEntity
Setting Cursor for App Engine Datastore using Java
Intermittent error org.hibernate.PersistentObjectException: detached entity passed to persist
Localizing a legacy product?
Java Set - how to sort based on a list of names
Android : Entries cannot be protected with passwords
MapReduce skipping the first line of input file
Maven. Adding maven repository for activiti

Categories

HOME
ms-access
cakephp
client
wso2-am
image
keras
hashmap
gis
setup-deployment
spring-jdbc
leon
microservices
c#-2.0
gps
windows-server
wamp
in-app-purchase
reveal.js
windows-server-2012
workload-scheduler
http-status-code-504
interop
shared-hosting
google-pagespeed
reverse-proxy
jasonette
dcevm
mustache.php
chromebook
libssl
google-cloud-nl
google-cloud-endpoints-v2
oracle-fusion-middleware
winrt-xaml-toolkit
form-data
bower-install
appfabric
streamsets
starteam
az-application-insights
document.write
streamreader
hp-ux
convertapi
btrace
smartcontracts
pango
theming
dotnetzip
aurelia-validation
libusb-win32
pdfclown
webdriverjs
redundancy
migradoc
azure-sdk
bstr
jwplayer7
pagerank
hsv
comobject
spidermonkey
iis-arr
security-testing
browser-bugs
ionic
appfabric-cache
p2
notify
inmobi
apache-commons-net
oxwall
asp.net-web-api-odata
eol
flexmojos
multiprocessor
excel-2003
jplaton
gwt-rpc
limejs
specification-pattern
distutils
viewswitcher
libc++
pydot
deobfuscation
hirefire
mod-auth
cinema-4d
blitz++
paster
preference
dbal
rescale
premature-optimization
post-build
msdev
django-notification
commodore

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App