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
lapo4ka [179]
4 years ago
13

Write a method that take an integer array as a parameter and returns the sum of positive odd numbers and sum of positive even nu

mbers.
Computers and Technology
1 answer:
elixir [45]4 years ago
6 0

Answer:

I will code in Javascript:

function sumOddAndEven(){

<em> //Define and initialize variables.</em>

var numbers = [1,2,3,4,5,6,7,8];

var sum = [0,0];

for ( var i = 0;  i < numbers.length ; i++ ){  <em>// loop to go throght the numbers</em>

<em> </em>if(numbers[i] > 0) {<em> // if the number is positive</em>

  if(numbers[i]%2 == 0) {  <em>// if number is even and </em>

     sum[0] = sum[0] + numbers[i];  <em>//adds in the first place of sum</em>

   }

   else{  

     sum[1] = sum[1] + numbers[i];  <em>// else adds in the second place of sum</em>

   }

 }

}

 return sum; <em>//return an array with the sum of the positive evens numbers  in the first place and the sum of the positive odd numbers in the second place.</em>

}  

You might be interested in
Implement the function printTwoLargest that inputs an arbitrary number of positive numbers from the user. The input of numbers s
meriva

Answer:

The function in Python is as follows:

def printTwoLargest():

   chk = 0

   list1 = []

   num = int(input("Enter: "))

   while num > 0:

       for i in list1:

           if i == num:

               chk+=1

               break;

       if chk == 0:

           list1.append(num)

       chk = 0

       num = int(input("Enter: "))

   list1.sort()

   if len(list1) >= 2:

       print("Largest:", list1[-1])

       print("Second:", list1[-2])

   else:

       print("Length of list must be at least 2")

Explanation:

This defines the function

def printTwoLargest():

This initializes a check variable to 0

   chk = 0

This initializes an empty list

   list1 = []

This prompts the user for input

   num = int(input("Enter: "))

The following loop is repeated until input is 0 or negative

   while num > 0:

<em>The following for loop checks for duplicate</em>

<em>        for i in list1: </em>

<em>            if i == num: </em><em>If duplicate is found</em><em> </em>

<em>                chk+=1 </em><em>The check variable is set to 1</em><em> </em>

<em>                break; </em><em>And the for loop is exited</em><em> </em>

The input is appended to the list if the check variable is 0 (i.e. no duplicate)

<em>        if chk == 0: </em>

<em>            list1.append(num) </em>

This sets the check variable back to 0, for another input

       chk = 0

This prompts the user for another input

       num = int(input("Enter: "))

This sorts the list

   list1.sort()

This prints the two largest if valid user input is 2 or more

<em>    if len(list1) >= 2: </em>

<em>        print("Largest:", list1[-1]) </em>

<em>        print("Second:", list1[-2]) </em>

if otherwise, this prints that the length must be at least 2

<em>    else: </em>

<em>        print("Length of list must be at least 2")</em>

3 0
3 years ago
Which network component blocks status?
SIZIF [17.4K]

Answer:

Router

Explanation:

It will reads the data packet's destination address .

Looks up all the paths it has available to get to that address.

7 0
3 years ago
What are some ways to rename a worksheet? Check all that apply.
Mamont248 [21]

Answer:

Click the Home tab, click Format, click Rename Sheet, type the name, and press Enter

Explanation:

im  not really sure but i think this is the answer

have a good day

3 0
3 years ago
Which generation language provides a graphical environment in which the programmer uses a combination of English-like instructio
zaharov [31]

Answer:

Procedural Language.

Explanation:

The procedural language used to create a program by using a programming editor or IDE, These graphical environment help users develop programming code, and fix bugs in the code.

8 0
3 years ago
Anna is making a presentation on the top five most visited cities in her state. she wants to make sure that she does not put in
andrey2020 [161]
Outline View. This view shows only the text of all the slides in the presentation on the left pane, enabling Anna to see whether she has put too much information or not.  She can also directly edit the the text  and simultaneously see its effect on the slide.  
8 0
3 years ago
Read 2 more answers
Other questions:
  • What is the role of the ieee in computer networking and wireless communications?
    14·1 answer
  • What online resource name does a major University end with
    7·2 answers
  • If you ask a question on this website, how do the points work? Meaning, the points that you set for the person who answers, does
    14·1 answer
  • Citing the recent increase in earnings by several computer companies, economists feel that a cycle has begun in which personal c
    13·1 answer
  • Money from a Coverdell Education Savings Account can be used for:
    11·1 answer
  • At one college, the tuition for a full-time student is $6,000 per semester. It has been announced that the tuition will increase
    7·1 answer
  • Which of the following processes demonstrates that matter is made up of minute particles? (A) Difussion (B) Capillarity (C) Dist
    15·1 answer
  • Use a for loop to output the numbers from 50 to 65
    6·1 answer
  • Printed versions of your presentation that contain the slides and blank lines below are called
    9·1 answer
  • Two negative reviews and no positive reviews is enough to consider the website to have a negative reputation.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!