How to add a group of integers [closed]
Can some one tell me how to do this and explain it to me: Write a program that reads a text file that contains groups of integers that start with the word “next”. For each group, the program computes and writes out the sum o开发者_如何学Pythonf integers in that group. There may be any number of groups.
I'm not asking you to do my home work, I need some one to explain it. I got stuck with the scanner
For the reading a text file bit, check out the Scanner class, which can parse your text file. Or alternatively, use a BufferedReader (Scanner will probably be much, much easier).
Since you have a variable number of groups, ArrayList can be useful for storing your groups of integers.
Hope this helps.
Agree on the homework warnings.
You will probably use a Scanner to read the file. Look at the javadoc for Scanner. There is also a method in Integer called parseInt which allows you to turn a string into an integer.
精彩评论