Does anyone know how to iterate over several input strings through Scanner in java, and play with each string in the given line | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Does anyone know how to iterate over several input strings through Scanner in java, and play with each string in the given line

for example Input : This That There, if I would Have to change char sequence of each word, how can I make the scanner process each word seperately

19th Dec 2019, 8:10 PM
ASM
ASM - avatar
6 Answers
+ 7
Mirielle๐Ÿถ [Inactive] Also,when I tried it with a do{ input. next() } while(input. hasNext()) ;, It worked like a gem, and processed every single string subsequently in the sentence with the given code, Thanks Again
20th Dec 2019, 5:42 AM
ASM
ASM - avatar
+ 6
Mirielle๐Ÿถ [Inactive] Thanks mirielle, looks like hasNext method was all I was looking for, Thanks for telling that with a while loop ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜„๐ŸŒน
20th Dec 2019, 4:04 AM
ASM
ASM - avatar
+ 5
~ swim ~ I've worked with scanner alot, but still can't say i thoroughly understand it when it comes to strings yet.
20th Dec 2019, 4:00 AM
ASM
ASM - avatar
+ 5
Jayakrishna thanks for this, but I was looking for a subtly more sophistocated method, as I wanted to process 'each' word with the given single input
20th Dec 2019, 4:02 AM
ASM
ASM - avatar
+ 2
Are you looking to "split" (that's a clue) the input into individual elements/words?
19th Dec 2019, 9:08 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Scanner is used to take only input values. so for taking input, If "scan" is scanner object, then use like. : scan.next() // accept a word. scan.nextLine() // accept total line as input.. After taking input, hoping you can do your remaining tasks.. Is it what you need?
19th Dec 2019, 8:25 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ