You are given a file, input.txt, that contains some even number of lines. Each line contains two values: a number and a string. For this task, you need to write a Java code to calculate the sum of the numbers in two consecutive lines of input.txt and write the sum in another file, output.txt. Check the following example for details: 123 100 50 50 45 55 input.txt output.txt Line 1: 223 Line 2: 100 Line 3: 100 Here, the first output is 223 which is equal to 123 + 100. The second output is 100 which is equal to 50 + 50 and so on. The three dots at the end of input.txt means that there are many more lines in the file.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
You are given a file, input.txt, that contains some even number of lines. Each line contains two values: a number and
a string. For this task, you need to write a Java code to calculate the sum of the numbers in two consecutive lines of
input.txt and write the sum in another file, output.txt. Check the following example for details:
123
100
50
50
45
55
input.txt
output.txt
Line 1: 223
Line 2: 100
Line 3: 100
Here, the first output is 223 which is equal to 123 + 100. The second output is 100 which is equal to 50+ 50 and so
on. The three dots at the end of input.txt means that there are many more lines in the file.
Transcribed Image Text:You are given a file, input.txt, that contains some even number of lines. Each line contains two values: a number and a string. For this task, you need to write a Java code to calculate the sum of the numbers in two consecutive lines of input.txt and write the sum in another file, output.txt. Check the following example for details: 123 100 50 50 45 55 input.txt output.txt Line 1: 223 Line 2: 100 Line 3: 100 Here, the first output is 223 which is equal to 123 + 100. The second output is 100 which is equal to 50+ 50 and so on. The three dots at the end of input.txt means that there are many more lines in the file.
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning