Question

Suppose that the following data is in the file Test2Data.txt (attached). 87 78 83 94 23...

Suppose that the following data is in the file Test2Data.txt (attached).

87 78 83 94

23 89 92 70

92 78 34 56

Use a loop to find the sum of the numbers in each line. For each line,output the numbers together with their sum as shown below.
87 78 83 94 sum = 342
23 89 92 70 sum = 274
92 78 34 56 sum = 260

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Scanner;

public class ReadFile {

   public static void main(String[] args) throws Exception {
       Scanner sc = new Scanner(System.in);
       BufferedReader br = new BufferedReader(new FileReader(new File("Test2Data.txt")));
       String line = br.readLine();
       int sum;
       while (line != null) {
           sum=0;
           //splitting Rinto tokens
           String arr[] = line.split(" ");
           //iterating through numbers and converting it into integers and adding to sum
           for(String s:arr)
               sum=sum+Integer.parseInt(s);
           System.out.println(line+" sum = "+sum);
           line = br.readLine();
       }
   }

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Suppose that the following data is in the file Test2Data.txt (attached). 87 78 83 94 23...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Pitcher 1 Pitcher 2 87 82 86 92 82 70 84 96 83 89 81 84 85 84 93 ...

    Pitcher 1 Pitcher 2 87 82 86 92 82 70 84 96 83 89 81 84 85 84 93 80 86 81 85 89 84 86 92 72 83 77 84 87 80 89 87 93 88 78 87 81 79 82 82 87 82 81 87 84 80 88 88 93 90 80 85 79 86 87 87 74 86 78 85 80 85 83 88 79 84 95 83 81 88 89 87 91 94 93 83 91...

  • 1) Given the data set below        25 52 68 23 78 89 56 90 32 78...

    1) Given the data set below        25 52 68 23 78 89 56 90 32 78        45 48 62 54 94 69 46 79 40 33        21 57 84 54 22 34 68 63 61 76        87 78 39 50 70 60 32 65 73 45        28 82 66 79 71 80 42 66 24 90 For the dada of Problem 1, find the approximate mean using the Frequency Distribution from problem 1 3) Find the Median of the data...

  • Write a python nested for loop that prints out the following pattern 100 99 98 97...

    Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...

  • Consider the below matrixA, which you can copy and paste directly into Matlab.

    Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...

  • The given data is the grades for people in this class. The goal here is to...

    The given data is the grades for people in this class. The goal here is to determine the factors that effect student's Grade in the class. 4) Find the mean and median for the men's and the women's Quizzes. Gender Men Women 5) Test the claim that the majority of students at this class are women. F M F F M F F F F M M F F F M F F F F M M F F M...

  • 1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand....

    1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand. b. Explain why you chose this technique over others. Year 3 Year 1 Year 2 Actual Actual Actual Forecast Forecast Forecast Demand Demand Demand Week 1 52 57 63 55 66 77 Week 2 49 58 68 69 75 65 Week 3 47 50 58 65 80 74 Week 4 60 53 58 55 78 67 57 Week 5 49 57 64 76 77...

  • A. Make a stem-and-leaf display for the following data. Comment about the shape of the distribution....

    A. Make a stem-and-leaf display for the following data. Comment about the shape of the distribution. 58    52    68    86    72    66    97    89    84    91    91    92 66    68    87    86    73    61    70    75    72    73    85    84 90    57    77    76    84    93    58    47 B. Construct a frequency distribution using 6 classes with the first lower class limit of 58, draw a Histogram, and what is the shape of distribution? 58, 60, 62, 63, 70, 71, 71, 76,...

  • I need to develop the 7 functions below into the main program that's given on top...

    I need to develop the 7 functions below into the main program that's given on top Write a C program to create array, with random numbers and perform operations show below. Il Project 3 (53-20). 1 Projects CS5,00 This file contains the function Programcution Dagine and one include <timo // Defining some constants definer_SIZE 20 define LOVE LIMIT 1 eine UPR UNIT define TALSE eine Tut 1 wold randomizery (int[], int, Int, int) wold pinay in. St, Int); En find...

  • Write a Python program (question2.py) that reads from a file called “input.txt” numbers in [1,39] separated...

    Write a Python program (question2.py) that reads from a file called “input.txt” numbers in [1,39] separated in by commas. The numbers are in [1-99]. The program will then convert each number to a possible Roman Numeral equivalent, and print it on the screen. Remember, I is 1, V is 5, X is 10 For example, if the input is: 23, 11 the output is: XXIII, XI. ROMAN NUMERALS CHART 1 TO 100 69 LXIX 11 2 11 3 III 4...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT