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
Will the fcc ruin the internet affect uk
n200080 [17]
No it will not the FCC is a federal owned company by the United States and has no control over any other servers outside of the US
3 0
3 years ago
If you’re the victim of cyber bullying behavior, besides contacting your teacher or the school, where else can you go to find in
RideAnS [48]

parents

childline

ceop

family

3 0
3 years ago
What is a current trend in ERP systems?
andre [41]

Answer:

C

Explanation:

The top trends to for in your ERP system include: Cloud Deployment, it is cloud adoption will continue to rise and become generally accepted with the most ERP systems.It is reduced costs in capital expenditures and ITcompany resources, then improved maintenance and flexibility, as well as improved the security.

5 0
3 years ago
These are Spealized graphics programs gor editing or modifying digital photographs
lisov135 [29]
They fall under the category of “Photo Editing Software” or “Image Manipulation Software”
8 0
3 years ago
which shortcut can we use to make directional heading of a cuboid more obvious while in the lidar view​
Lady bird [3.3K]

Answer:

cutting across

Explanation:

4 0
3 years ago
Other questions:
  • What is the Multiplier if the change in RGDP is $525,000,000 and initial spending is $100,000?
    12·1 answer
  • The name of the opening that lets light into any camera is called ________.
    11·2 answers
  • With a ____ indent, all lines except the first line of the paragraph are indented from the left margin.
    12·1 answer
  • How can i turn on my prinfer without getting up
    12·2 answers
  • A new company will have 40 workstations in one building sharing a single network. All users must be able to share ¬les and print
    7·1 answer
  • Tribology is a branch of physics concerned with friction in mechanical motion. Knowledge of tribology would be useful working wi
    14·1 answer
  • Develop Swimlane Activity diagram for Assignment announcement and submission system.
    6·1 answer
  • In case of a suspected data breach, what course of action should a chief information security officer (CISO) take
    9·1 answer
  • Is there any website online to use android studio live?​
    11·1 answer
  • How can a classroom be more effective by the use of multimedia? ​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!