简体   繁体   中英

How do i print a line from an imported text file in java if the inputted int is found in that text file?

I'm making a Java "text clock" that prints out the inputted value in English eg

input: 15:30 
output: fifteen thirty

my text file is holding

01= one 
02= two 
03= three
...
15= fifteen and so on

Is there a way I can link the text file with my java program so that when let's say 01 is inputted by the user. The program will look for 1 in the text file and print out "One". Would this be possible to do

Here are the steps you need to follow:

  • Try creating a map that reads the file whose key would be String (a number representation) and value would be string representation.
  • Read the user input and split it by ":" which will give you an array of length two.
  • Look up in a map for number before ":" ie array[0] and print it
  • Look up in a map for number after ":" ie array[1] and print it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM