1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gnom [1K]
3 years ago
6

Write a program that asks the user to enter a series of numbers separated by commas. Here is an example of valid input: 7,9,10,2

,18,6 The program should calculate and display the sum of all the numbers.

Computers and Technology
1 answer:
alex41 [277]3 years ago
8 0

Answer:

Here is the JAVA program. Let me know if you need the program in some other programming language.

import java.util.Scanner; // used for taking input from user

public class Main{ //Main class

public static void main(String[] args) {//start of main() function body

  Scanner scan = new Scanner(System.in); // creates a Scanner type object

   String input; // stores input series

    int sum = 0; //stores the sum of the series

    System.out.println("Enter a series of numbers separated by commas: "); //prompts user to enter a series of numbers separated by comma

     input = scan.nextLine(); //reads entire input series

     String[] numbers = input.split("[, ]"); //breaks the input series based on delimiter i.e. comma and stores the split sub strings (numbers) into the numbers array

   for (int i = 0; i < numbers.length; i++) { //loops through each element of numbers array until the length of the numbers reaches

          sum += Integer.parseInt(numbers[i]); } // parses the each String element of numbers array as a signed decimal integer object and takes the sum of all the integer objects

     System.out.println("Sum of all the numbers: " + sum);  } } //displays the sum of all the numbers

Explanation:

The program prompts the user to enter a series separated by commas.

Then split() method is used to split or break the series of numbers which are in String form, into sub strings based on comma (,) . This means the series is split into separate numbers. These are stored in numbers[] array.

Next the for loop iterate through each sub string i.e. each number of the series, converts each String type decimal number to integer using Integer.parseInt and computes the sum of all these integers. The last print statement displays the sum of all numbers in series.  

If the input is 7,9,10,2,18,6

Then the output is: 7+9+10+2+18+6

sum = 52

The program and its output is attached.

You might be interested in
Images are available in many formats, such as tif, bmp, gif, jpeg, and ____.
Lerok [7]
<span>Images are available in many formats, such as tif, bmp, gif, jpeg, and png.

</span>Hope that helps.
7 0
3 years ago
How to reload ingenuity when a pulsating blue thing is there
Hatshy [7]
Todo is very important
4 0
3 years ago
Which are characteristics of interpreters? Select
SVEN [57.7K]

Answer:

translation is used for interpretation

8 0
3 years ago
Read 2 more answers
Which of the following is not true about network design?Group of answer choicesIn designing LAN networks, network designers tend
sergey [27]

Answer:

In designing LAN networks, network designers tend to design err on the side of providing for less capacity than what is currently necessary.

Explanation:

In designing LAN networks, network designers tend to design err on the side of providing for less capacity than what is currently necessary is not true about network design.

8 0
3 years ago
Use these sentence starters to explain how Cat Insanity is an analogy for debt repayment.
denpristay [2]

Answer: Can Insanity is like a debt repayment, if you don't pay or feed it on time they will die/ interest rate of the bank will be more and more expensive.

Explanation:

7 0
3 years ago
Other questions:
  • Question: Henry wants to change the configuration information of an application. Which file should Henry edit to change this inf
    15·1 answer
  • A prediction or statement that can be tested is ____
    9·1 answer
  • Electricity was seen as a mysterious force and began to creat a stir when people called​
    13·1 answer
  • A sentinel value ________ and signals that there are no more values to be entered:____
    14·1 answer
  • Why does brainly keep saying “oops... something went wrong! Try again”
    7·2 answers
  • Justin has started a lawn mowing business in his neighborhood. He is running a weed-pulling special this month. What is the most
    8·2 answers
  • Mobile app designers who work for themselves are often dubbed _____.
    10·1 answer
  • If I wanted to repeat an action such as a heading for a paper, it would be helpful to _____. create a citation create a caption
    9·2 answers
  • Why is Linux widespread in academic environments?
    7·1 answer
  • Eli needs to export files from his mailbox into a single file that is portable and can be backed up to removable media. Which fi
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!