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
Design a class named Employee. The class should keep the following information in fields: Employee first name Employee last name
mixer [17]

Answer:

Explanation:

The following is written in Java and creates the Employee class with the variables requested and a getter setter method for each variable

package sample;

public class Employee {

   private String lastName, firstName, idNumber;

   

   public void Employee() {

   }

   public String getLastName() {

       return lastName;

   }

   public void setLastName(String lastName) {

       this.lastName = lastName;

   }

   public String getFirstName() {

       return firstName;

   }

   public void setFirstName(String firstName) {

       this.firstName = firstName;

   }

   public String getIdNumber() {

       return idNumber;

   }

   public void setIdNumber(String idNumber) {

       this.idNumber = idNumber;

   }

}

8 0
2 years ago
What's the minimum storage for onedrive e2
cupoosta [38]
It should be 1 TB per user
3 0
3 years ago
Which of the following is not a SQL*Loader file?
MatroZZZ [7]

Answer:

D. Good file

Explanation:

SQL loader is responsible for loading data from files into the database. It needs the mandatory control file, bad file, log file and an optional discard file.

A. Bad file

This file shares its name with the data file and has .bad extension.

The bad file holds all the records which are rejected ( bad data ). If a bad file is not available, it is automatically created. The data is either rejected by the SQL loader or by Oracle itself. The rejected records are not placed in the data file and hence, have to be placed in the bad file.

It is mandatory to have a bad file for every data file.

B. Control file

This is a mandatory file. This is a text file needed by the SQL loader to perform the loading process.

It contains the information related to location of data, specifies the criteria for selecting data for insertion, location for inserting data, and the like.

C. Discard file

The discard file is created if the need arises. This is not a mandatory file to be present.

The data which is discarded and gets filtered out, is placed in the discard file.

The data is not inserted in the table because it does not matches the criteria for the data to be inserted.

This criteria is mentioned in the control file.

The data is discarded only due to the mismatch and not because it is rejected or is bad data.

E. Log file

This file is mandatory to the execution. In absence of log file, the loader does not proceeds with execution and gets terminated.

In the beginning of the execution, a log file must be created by the loader. This file contains all the information regarding the data loading and also the errors encountered during the loading process.

6 0
3 years ago
What is storage devices?​
Yuliya22 [10]

Answer:

A storage device is a device used to keep softcopy for future reference

3 0
3 years ago
Read 2 more answers
Give the full form of http​
astraxan [27]
Hypertext Transfer Protocol
h is for hyper
the T in text is the first T
transfer is the second T
and P is for protocol

HTTP hope that helps
8 0
2 years ago
Other questions:
  • A strategy to solve a logic problem is to break it into steps. Using the drop-down menu, complete these sentences about solving
    15·2 answers
  • When does personal information often need to be entered online?
    15·1 answer
  • If anyone gotta ps4, i'm a 15 yr old female n if u wanna b frens, hmu :))
    8·2 answers
  • What is Digital Citizen? It's one of my classes.
    5·1 answer
  • Where did the name "QWERTY" come from?​
    9·1 answer
  • The optical phenomenon that allows us to view rapidly changing still images as moving images is called _______.
    15·2 answers
  • What impact download speeds on different computers
    13·1 answer
  • Can someone please help???
    6·1 answer
  • A trace table is used for
    5·2 answers
  • Basics of visual basic
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!