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
lara31 [8.8K]
3 years ago
13

Write a function addOddMinusEven that takes two integers indicating the starting point and the end point. Then calculate the sum

of all the odd integers minus the sum of all even integers between the two points. The calculation includes the starting point but excludes the end point. You can always assume the starting point is smaller than the end point.
Computers and Technology
1 answer:
snow_lady [41]3 years ago
8 0

Answer:g

   public static int addOddMinusEven(int start, int end){

       int odd =0;

       int even = 0;

       for(int i =start; i<end; i++){

           if(i%2==0){

               even = even+i;

           }

           else{

               odd = odd+i;

           }

       }

       return odd-even;

   }

}

Explanation:

Using Java programming language:

  • The method addOddMinusEven() is created to accept two parameters of ints start and end
  • Using a for loop statement we iterate from start to end but not including end
  • Using a modulos operator we check for even and odds
  • The method then returns odd-even
  • See below a complete method with a call to the method addOddMinusEven()

public class num13 {

   public static void main(String[] args) {

       int start = 2;

       int stop = 10;

       System.out.println(addOddMinusEven(start,stop));

   }

   public static int addOddMinusEven(int start, int end){

       int odd =0;

       int even = 0;

       for(int i =start; i<end; i++){

           if(i%2==0){

               even = even+i;

           }

           else{

               odd = odd+i;

           }

       }

       return odd-even;

   }

}

You might be interested in
âwhat service uses a private cloud in conjunction with a web browser or downloaded client software to access desktop software?
Vera_Pavlovna [14]
<span>The answer should be: Virtual Desktop Infrastructure</span>
5 0
4 years ago
To get a sense of your digital footprint, you should:
Serggg [28]
Google yourself once a year.
4 0
4 years ago
Read 2 more answers
Help, with gaming unlocked
Leto [7]

Answer:

C. empathic understanding

8 0
4 years ago
A method signature for a method consists of all elements of the method except the body. That is, a method signature consists of
Bess [88]
To be honest I feel like it’s B that’s looks and seems the most correct to me
8 0
3 years ago
Given a one dimensional array arr, what is the correct way ofgetting the number of elements in arr
SVETLANKA909090 [29]

Answer:

The answer is option 1 arr.length.

Explanation:

In java arr.length gives the correct number of elements in the array.The length is function is only applicable for arrays.

The length() method is applicable for strings.

arr.length-1 will give 1 element less.

There is no .size for arrays in java.

So we conclude that arr.length is correct way of getting the number of elements in one dimensional array arr.

3 0
4 years ago
Other questions:
  • Extend the flow properties and definitions to the multiple-source, multiple- sink problem. Show that any flow in a multiple-sour
    13·1 answer
  • Why do primitive types have ranges of values? what determines the range of the data type?
    15·1 answer
  • Assume:
    14·1 answer
  • Body paragraphs in a report have a first-line indent of _____ inch. *
    9·1 answer
  • 1. We want to add a button to the tally counter in Section 9.2 that allows an operator to undo an accidental button click. Provi
    8·1 answer
  • /* Write a method called fractionSum that accepts an integer parameter n and
    5·1 answer
  • What is a sequence of graphic illustrations which represent the planned scenes for a video or animation?
    6·2 answers
  • List the steps to create a new folder in windows
    13·1 answer
  • This assignment is based on Exercise 8.4 from your textbook. Each of the following Python functions is supposed to check whether
    11·1 answer
  • What is a use case of factorization in quantum computing?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!