Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Delimiter Scanner class  RSS feed

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the following code is a  snippet of code of book OCA8


it'is compile successufly and when i run it, it print the result:
"<X4>< we were><8><:-)><2C><1>"
really i don't undrestand why this print?
 
Marshal
Posts: 13443
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is like a puzzle, isn't it? Like a Rubik's cube, I mean. Just like a Rubik's cube, you have to solve it one step at a time.

I suggest going to JShell, Java's REPL environment and experiment with each of these statements.
C:\ > jshell
|  Welcome to JShell -- Version 11.0.1
|  For an introduction type: /help intro

jshell> Scanner lexer = new Scanner("X4, we were||m8s & :-) 2C,1 THR,")
lexer ==> java.util.Scanner[delimiters=\p{javaWhitespace}+] ... \E][infinity string=\Q∞\E]

jshell> lexer.useDelimiter("[|,]")
$2 ==> java.util.Scanner[delimiters=[|,]][position=0][match valid=false][need input=false]
[source closed=false][skipped=false][group separator=\,][decimal separator=\.]
[positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=]
[NaN string=\QNaN\E][infinity string=\Q∞\E]

jshell> "<" + lexer.next("\\w*") + "><" + lexer.next() + ">"
$3 ==> "<X4>< we were>"

... and so on ...

Notice that you don't need to use System.out.println() to print an expression, just enter the expression directly and the REPL will do its thing to read, eval, and print the value of the expression.

 
Would you like to try a free sample? Today we are featuring tiny ads:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!