#How do I count how many 0's are in a scanner?
39 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @wise kraken! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
and then they give us this line
which is like a string right?
kinda?
so im thinking i need to use a delimiter or split/trim functions
but idk where to start this
The entire point of Scanner is that it delimits them for you. Just call next()
oh.. so if i have that split, how do you filter out an int vs double like 0 vs 0.0
There are many approaches, but you could try hasNextInt() and hasNextDouble() before hasNext()
wait so does it automatically turn each thing into its proper variable?
like int double string
has-stuff checks whether the String that would be obtained with next() has a format that works for the mentioned stuff
If you want to read with the conversion, it's nextInt() or nextDouble() and so on
if hasNextInt() => if nextInt() == 0
For example. I'm not entirely sure what counts as a zero in the assignmet
just the int 0
not 0.0 or string0 or whatever
so while scan.hasnext
and then if scan.hasnextint?
Then just read the String without caring whether it's an int, double, word or whatever
ok maybe my code on top doesnt make sense and im just experimenting
but with this print statement
how do i get it to recognize that scan =2?
is that what im doing by making space0space string