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
Write a program great_circle.python that takes four float arguments x1 y1 x2 y2
svlad2 [7]

Answer:

897893+ 892e98374))8qwye932__8730140923(7834983(8974+9)9903)

Explanation:

IT IS SIMPLE MY FRIEND

spanish conquistadors, who were primarily poor nobles from the impoverished west and south of Spain, were able to conquer the huge empires of the New World with the help of superior military technology, disease (which weakened indigenous resistance), and military tactics including surprise attacks and powerful and there were no strangers to love and they knew the rules and so did i they just wanted to tell people how the were feeling and they wanted someone to understand so they were never gonna give you up and they were never gonna let them down and they were never gonna turn around and hurt other people in the army they were never gonna make the soldiers cry and they never were going to say goodbye but the years stop comming and they dont stop comming head to the rules gotta keep the groud running but Remember those walls I built Well, baby, they're tumbling down And they didn't even put up a fight They didn't even make a sound I found a way to let you win But I never really had a doubt Standing in the light of your halo I got my angel now It's like I've been awakened Every rule I had you breaking It's the risk that I'm taking I ain't never gonna shut you out Everywhere I'm looking now I'm surrounded by your embrace BabPatrician. Patricians were considered the upper-class in early Roman society. They controlled the best land and made up the majority of the Roman senate.y, I can see your halo You know you're my saving grace You're everything I need and morei t's written all over your face Baby, I can feel your halo Pray it won't fade away  Hit me like a ray of sun Burning through my darkest night I'm boutta' pop,  you know I'm boutta' blow up Only need these hands I don't need no  pole Once I get a grip, I might blast yo  dome up Like I'm Bakugo, turn they soul to  smokei 'm boutta' pop,  you know I'm boutta' blow up Only need these hands, I don't need no ' pole Once I get a grip, I might blast yo dome up Why you packin', you ain't bout' that action I'll blow her back in Why you mad but not attackin' boy I'll send you packin' I'm the best, no doubt about it Competition live without it You just mad cause I'm too rowdy get back I'm really bout it Head down on the ground, you don't want these hands around you Nitroglycerin I'm sweatin', blastin' off I'm bound to Rushin', there ain't no hiding yous a  if you down to If you try to hide you gon' be begging once I've found you I'm the best, ain't no hero but always been vet if you got an issue, AP shots up to yo neck I don't give a  about no one, I'll say it no regrets I'm only here for me, I'm at the top and you'll respect Grenadier bracers on my wrist, I'm about to pull the pin Come at me with all your might or I'ma melt off all your skin Howitzer impact  ,  I told you I'ma win get back before I blast, I said I'll do it again wit' a grin Like I'm Bakugo, turn they soul to ' smoke I'm boutta' pop,  you know I'm boutta' blow up Only need these hands I don't need no  pole Once I get a grip, I might blast yo  dome up and  I want Think I'm addicted to your light  swore I'd never fall again But this don't even feel like falling Gravity can't forget To pull me back to the ground again Patric Patrician. Patricians were considered the upper-class in early Roman society. They controlled the best land and made up the majority of the Roman senate.ian. sorry teacher but i am gay They also needed to pack it box it flip it top it wit a bowtie ribbion stop it because there dogs were eating all the rainbow cookies and pies were filying through the roof. Patricians were considered the upper-class in early Roman society. They controlled the best land and made up the majority of the Roman senate.

6 0
3 years ago
How much cell phone data does the average person use a month
azamat
It all depends on what you're doing online.
7 0
3 years ago
Answer for a, b, and c
Darya [45]

The answer is a. im pretty positive but if im wrong super sorry

5 0
3 years ago
my pc wants to run the highest graphics even though I restart it everyday and it gets around 10 fps and I have a 1080 Nvidia gra
Luden [163]

Answer:

you have to restart the rom , if that doesnt work , start the ram

Explanation:

5 0
3 years ago
What does a cargo and freight agent do
ss7ja [257]

<em>Hey there!</em>

<em />

Well cargo and freight agents expedite and route movement of incoming and exporting cargo and of course freight.

<em>Hope this helps :)</em>

7 0
2 years ago
Other questions:
  • Which of the following statements is false? a. Each object of a class shares one copy of the class's instance variables. b. A cl
    11·1 answer
  • Q10: Putting it all together (0.75 points) Here, we'll update the values in dictionary, storing the output in a dictionary calle
    5·1 answer
  • Design a circuit that has a 3-bit binary input B2, B1, B0 (where B2 is most significant bit and B0 is least significant bit) and
    14·1 answer
  • While speech recognition can operate without any confi guration, you can train it to more accurately recognize your voice. true
    5·1 answer
  • The "fathers of the Internet" are Vinton Cerf and ________. Select one: A. Tim Berners-Lee B. Bill Gates C. Robert Kahn D. Rober
    8·1 answer
  • User Interface Design ensures that the interface has elements that are easy to ________________. (Choose all that apply)
    10·2 answers
  • List the difference between GIGO and bug ​
    15·1 answer
  • WHICH PROGRAMMING LANGUAGES ARE THE BEST FOR PROGRAMMING?
    14·1 answer
  • Where are 'if' and 'else' statements shown when printing a document in a word processor?
    8·1 answer
  • (ATRCKALLB) __________is an input device that contains a movable ball on the top.​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!