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

How to merge two .apk files and make one .apk file? [duplicate]
Check Is the array is empty in one line
Swing splash screen not working, Unexpected result
cucumber step definitions are not being located
Big O: what is the time complexity for this algorithm?
Splitting a Decimal Value(as String ) using java
Dynamically set XML URI at runtime - XSLT option
Extract text from html file using java
Multiple servlet mappings in Spring Boot
Cannon Find Symbols Error
View.Listener is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
XML parsing throwing NullPointerException
How can I display one type of formatting in GWT application?
'javax.xml.parsers.FactoryConfigurationError: Provider for class javax.xml.parsers.DocumentBuilderFactory cannot be created' for Tomcat Valve
Why protected member variables are considered an anti-pattern and should be replaced with private access fields?
How to make google play games optional?

Categories

HOME
ionic-framework
date
mediawiki
relayjs
youtube-dl
cmd
leon
rubygems
contact
add
synchronization
amazon-cloudformation
applepay
etl
google-apps-marketplace
timeout
vaadin7
workload-scheduler
django-admin
contextmenu
dbext
immutable.js
object-detection
mps
extjs5
core-text
centos6.5
windows-error-reporting
maxmind
elasticsearch-net
atlassian-crucible
jaxb2
webkitspeechrecognition
kendo-datasource
procdump
preg-match-all
data-manipulation
http-get
vsts-build-task
amazon-kinesis-kpl
plsql-psp
streamreader
particles.js
sql-server-agent
quadratic-programming
node-gyp
estimote
segment
wptoolkit
dandelion
recursive-datastructures
np-complete
flow-control
sqldf
visual-c++-2008
spring-android
removechild
android-textview
savon
elements
trash
google-web-starter-kit
merge-conflict-resolution
iad
t4mvc
comobject
jqgrid-formatter
apache-commons-fileupload
unity5.2.3
truevault
network-interface
nsbutton
gulp-less
html-helper
article
starcluster
uitouch
stxxl
commoncrypto
soundtouch
opcache
pushbackinputstream
delphi-6
selected
libstdc++
automount
appconkit
ticoredatasync
reddot
hamachi
rfc1123
appender
celltable
propagation
filtered-index
memory-size
libs
mtj
nerddinner
geneva-server
dbisam
.net-1.0
paul-graham

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