java - How can I get different data types from the keyboard in just one line? -


i need keyboard in 1 line this:

create 1000 john 4000   

(for cinema program, include function create users)

where "create" command create new user (create class, , contains client information), "1000" id of user (int), "john" name(string), , "4000" points(int)

how can different data types in 1 line stored in different attributes client?

i use scanner object based on system.in read line in, using if (myscanner.hasnextline()) , myscanner.nextline() method pairs.

then line need parsed, , here i'd offer 2 possible ways:

  • consider using new scanner based on line read in, string variable called line, "line scanner" speak, scanner linescanner = new scanner(line), , tokens via linescanner.next(), linescanner.nextint(), linescanner.next(), , linescanner.nextint(), in order. don't forget close() linescanner when done using it.
  • or use string#split(" ") split string array of 4 substrings separated space.

then in loop parse line, create object needed based on data obtained.


Comments

Popular posts from this blog

My HTML document is not linking to my CSS stylesheet properly -

php array slice every 2th rule -

node.js - Sending sockets to client side, Error: Converting circular structure to JSON -