Hi Everyone! I'm pretty new here and to java programming as well.
I was wondering if u guys could help me out. I got this program below... it compiles and runs.
The problem it adds all the numbers together and than returns the total value, what I would like it to do is get the sum of the numbers on each line only. So instead of getting one number (which is what I am getting) how do I get the sum of each line?
import java.io.*;
import java.util.*;
class FileTest
{
public static void main (String[] args)
{
Controller contr = new Controller();
System.out.println (contr.getSum());
}
}
class Controller
{
FileAccess fa = new FileAccess();
public int getSum()
{
int lineNum = 1;
int sum = 0;
String lineOfText;
This looks an awful lot like a "modify this program to..." homework, so I'm not going to just give you the solution - it won't benefit you in the long run.
However, it's not very difficult to modify the getSum() method to return the sum of each line (about four lines of code I think).
How do *you* think it should be done? Once you've answered that question, we'll start talking specifics.
Bookmarks