简体   繁体   中英

Reading file and setting to variable

I'm new to programming, so I was wondering if someone could help me. What I'm trying to is make the user input a number, and if the number is in the file, it'll spit something back out, and if it's not in the file, it'll keep asking for a number. I don't know exactly how to do this, but if someone could point me in the right direction, that would be great. Thanks in advance!

  • First read the file and store it (as a Collection , or as a big String , the exact type depends on how you actually trying to achieve this).
    Reading a file can be done in numerous ways, some of them are using a Scanner , BufferedReader or File.readAllLines()
  • Now, create a while loop - that repeatidly asks the user for a number, until the condition that the number is in your data is met.
  • Next, you need to process and yield the desired output.

Bonus:
Try to do each of the bullets in a different method and only combine them in your main() - it will help you to learn about basic methods design as well.

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