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
Kay [80]
2 years ago
7

How to add up multiple user inputs for example: If i ask the user How many numbers do you want to add? they say 5 then i out put

Enter 5 numbers: how can i get it to add up those 5 numbers that were input.In JAVA
Computers and Technology
1 answer:
Morgarella [4.7K]2 years ago
6 0

Answer:

import java.util.Scanner;

class Main {

 public static void main(String[] args) {

   Scanner scanner = new Scanner(System.in);

   System.out.println("How many numbers do you want to add?");

   int numberOfNumbers = scanner.nextInt();

   int arrayNumbers[] = new int[numberOfNumbers];

   System.out.println("Enter " + numberOfNumbers + " numbers:\n");

   for(int i = 0; i < numberOfNumbers; i++){

     int addToArray = scanner.nextInt();

     arrayNumbers[i] = addToArray;

   }

   int sum = 0;

   for(int j = 0; j < arrayNumbers.length; j++){

     sum+=arrayNumbers[j];

   }

   System.out.println("Sum: " + sum);

 }

}

Explanation:

You might be interested in
What is output by the following line of code?
astraxan [27]

Answer:int x = 5;

if(x < 5)

cout << "line 1 ";

cout << "line 2";

A. line 1 line 2 B. line 1 C. line 2

D. line 1 E. line 1line 2

line 2

2. What would be output by the following code? _______

int x = 0;

while(x < 5)

{

cout << x << " ";

x++;

}

A. 0 1 2 3 4 5 B. 1 2 3 4 5 C. 0 1 2 3 4

D. 0 E. 0 0 0 0 0

3. After execution of the following code, what will be the value of input_value if the value 3 is entered at the keyboard at run time? ________

cin >> input_value;

if (input_value > 5)

input_value = input_value + 5;

else if (input_value > 2)

input_value = input_value + 10;

else

input_value = input_value + 15;

a. A. 8

b. B. 13

c. C. 18

d. D. 0

e. E. 5

4. What would the user see displayed on the screen after the following lines of code are executed?¬¬________

int i = 6;

if (i == 10)

cout << “value: “ << i;

else

cout << "hmmm";

A. value: i B. value: 10

C. hmmm D. value: ihmmm

E. value: 10

Hmmm

5. What is the output of the following lines of code? ______

for(int i=0; i<4; i++)

cout << (i * 3) << " ";

A. 0 1 2 3 4 B. 0 3 6 9

C. 0 3 6 9 12 D. 0 1 2 3 E. 0 0 0 0

Explanation:

6 0
2 years ago
All of the following are true about data science and big data except: a.Digital data is growing at the rate of 2.5 quintillion b
Firlakuza [10]

Answer:

Option C

Explanation:

All of the following are true about data science and big data except No digital data is stored in traditional databases

Reason -

Data generated in current time is of large size and is also complicated. Traditional data bases such as SQL databases etc. are not capable to store  data that is changing at a fast pace and has huge volume, veracity, variety and velocity. But big data platforms such as Hadoop can store big data and process it speedily and easily.

3 0
3 years ago
A ___ block unauthorized access to a network or an individual computer
valkas [14]
Firewall is the answer.
3 0
3 years ago
Users of an access point share the transmission capacity of the access point. The throughput a user gets is called the ________.
sdas [7]

Solution:

Users of an access point share the transmission capacity of the access point. The throughput a user gets is called the bits per seconds.

Thus this is the required answer.

6 0
3 years ago
1. Write a class for time objects that store three integer values for hour, minute, and second. Also, write a program to test th
Alla [95]

Answer:

1.

class TIME

{

int hour , min , sec ;

public :

TIME()

{

hour=min=sec=0;

}

TIME( int h , int m , int s )

{

hour = h;

min = m;

sec = s;

}

void change ( int Hour)

{

hour = Hour;

}

void stdtime()

{

if(hour>12)

cout<<"The Standard time is"<<(hour-12)<<":"<<min<<":"<<sec<<"P.M\n";

else

cout<<"The Standard time is"<<hour<<":"<<min<<":"<<sec<<"A.M\n";

}

void miltime()

{

cout<<"The Military time is"<<hour<<":"<<min<<":"<<sec<<" hours\n";

}

};

void main()

{

TIME A , B(13,25,30);

A .stdtime();

A.change(23);

A.miltime();

B.stdtime();

B.change(9);

B.miltime();

}

2.

class elevator

{

int CurrentFloor;

int GoingUp;

int GoingDown;

public:

elevator()

{

CurrentFloor=0;

GoingUp=1;

GoingDown=-1;

}

elevator(int floor)

{

CurrentFloor=floor;

GoingUp=1;

GoingDown=-1;

}

void goUp(int y)

{

if( CurrentFloor>3)

cout<<"\nNO MORE FLOORS\n";

else

CurrentFloor=CurrentFloor+y*GoingUp;

}

void goDown(int x)

{

if(CurrentFloor<0)

cout<<"\nNO MORE FLOORS";

else

CurrentFloor=CurrentFloor+x*GoingDown;

}

};

void main()

{

elevator A(1);

A.goUp(1);

A.goUp(1);

A.goUp(1);

A.goDown(1);

A.goDown(1);

}

6 0
3 years ago
Other questions:
  • Write a program that displays the following pattern: ..\.\* .\.\*** \.\***** ******* \.\***** .\.\*** ..\.\* That is, seven line
    8·1 answer
  • Which one of the following will not be considered as a microcomputer?
    12·2 answers
  • The entire presentation can be seen at a time in __________
    5·1 answer
  • Callie Crystal owns and operates one of the most successful local coffee shops in Denver, called The Edgewater Café. Each time a
    5·2 answers
  • Here is the problem specification: An Internet service provider has three different subscription packages for its customers: Pac
    5·1 answer
  • You are asked to write a program that prompts the user for the size of two integer arrays, user input for the size must not exce
    13·1 answer
  • Risk taker positive or negative​
    8·1 answer
  • 45 points!
    10·2 answers
  • In the following shell scripting extract, the initial values of variables s, c and p are 0, 1, 1 respectively. What will be the
    6·1 answer
  • Where else can the computer send the results of processing other than to output​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!