Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Can someone please help me with computer programming?
Say that a text file looks like this:
x= 10
y= -45
y= 98
x= 13
x= 37
y= 36
x= -2
. . .
Each line starts with "x=" or "y=" but which of these it starts with follows no pattern. Each of these is followed by a space then a single integer. Nothing else follows the integer on a line.
Write a program that reads in this data file and computes the sum of the x values and the sum of the y values. Hint: use hasNext() and next() to read the "x=" and "y=" tokens and then use nextInt() to read the integer. You will also need the equals() method of String.
I need major help can someone help me any way possible
1 Answer
- 8 years agoFavorite Answer
First thing is to create a loop that will run for every line in the file.
Inside that loop, you will want to read line N (where N is the current iteration of the loop) from the file, and determine if it's X or Y. Now you should take the integer from that same line, and add it to the correct variable.
Finally, after the loop finishes, you should display the values of X and Y.
I can't give you any specific commands, as I don't know what language you're using, and I can't give you a full program because this looks like your homework.
Source(s): Currently enrolled as a programming student.