开发者

How to add a group of integers [closed]

开发者 https://www.devze.com 2023-02-18 22:35 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号