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
(ACCESS 2016)
galben [10]

Explanation:

rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.

7 0
3 years ago
Read 2 more answers
Which device doesn't have wifi support? option (1) smartphone, (2) network printer, (3) table fan ​
Ne4ueva [31]
<h2><u>T</u><u>ABLE </u><u>FAN</u></h2>

Because it runs on electricity not by wi - fi.

5 0
3 years ago
Can someone write an essay on data storage and describe the different storages I have listed below•
Jobisdone [24]

Answer:

Explanation:

Punch card is the oldest computer storage; followed by tape and then floppy disk. Hard drive goes back as far as floppy but is still in use today. CD/DVD/BR discs are all later storage but are also used for storing music and videos. USB flash, SD card, SSD and cloud storage are the common technologies used today for data storage.

4 0
3 years ago
Read 2 more answers
What are some of the strategies that you use for confronting a complex problem and breaking it down into smaller pieces? How mig
bazaltina [42]

Answer:

Breaking it down I guess for me, you could take down all the possible things that you could do. Eliminating things, one by one. It could help working on a computer by not letting yourself get over-whelmed by all your programming and thinking "alright, this THEN this."

Explanation:

8 0
3 years ago
A low-pass first-order instrument has a time constant of 20ms. Find the frequency,in hertz, of the input at which the output wil
Lubov Fominskaja [6]
A design was operating at a maximum clock frequency of f and the clock had no jitter. if the clock started to have jitter of t secs, what will be the new frequency?
5 0
3 years ago
Other questions:
  • Why does the hp computer not have Bluetooth?
    6·1 answer
  • The bias condition for a transistor to be used as a linear amplifier is called:________.
    14·1 answer
  • Angela's ready to get started with her first Smart Display campaign, but her account isn't yet eligible due to not having enough
    11·1 answer
  • You are starting a spreadsheet, and you would like 500 to appear in cell C3. You should _____.
    11·2 answers
  • Which command should you enter to configure a single port to discard inferior bpdus 200-125?
    5·1 answer
  • You modify a document that is saved on your computer. Where are the changes stored until you save the document?a. Radom access m
    15·1 answer
  • At the Transport layer of the OSI, what is used to find and communicate with a particular application running on a host?
    7·1 answer
  • What provision of the Government Paperwork Elimination Act was designed to encourage a paperless society?
    6·2 answers
  • Write an algorithm and flowchart to display H.C.F and L.C.M of given to numbers.​
    9·1 answer
  • You are querying a database of manufacturing company suppliers. The column name for supplier identification numbers is supplier_
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!