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
Help!!
forsale [732]

Answer:

Explanation:

   In iOS 13 or iPadOS 14 or later go to Settings > account name > Find My > Find My iPhone/iPad, and disable Find My network.

   In macOS 10.15 Catalina or later, go to the Apple ID preference pane, select the iCloud link at left, click the Options button to the right of the Find My Mac item, and uncheck Offline Finding or Find My network (the text varies by macOS version).

7 0
2 years ago
Which animation principle is applied to ‘sell’ the beginning of the character jump?
Sunny_sXe [5.5K]
Anticipation I think so but I’m not sure:)
3 0
2 years ago
Choose the types of work a person in the network systems administration field might do on a regular
solniwko [45]

Answer:troubleshooting the network when there are problems with the connectivity ||||||| improving network speed

Explanation:

7 0
3 years ago
Read 2 more answers
A specailized output device for producing charts, maps, and very high-quality drawings is a? ​
Irina18 [472]

Answer:

a plotter

Explanation:

8 0
3 years ago
A systems analyst attended a week-long workshop on Agile software development. When she returned to her job, she told her boss t
Alexxandr [17]

Answer:

The answer is "disagree"

Explanation:

The system analyst is responsible, who uses research and methods of solving industrial problems with IT. He or she may act as representatives of change that identify, that process improvements needed design systems for such improvements, or inspire us to use systems.

  • Analysts testing and diagnosing issues in operating systems for QA applications and the programmer analyst design and write custom software, that satisfy the requirements of their employers or customers.
  • For the system analysis, the analyst uses all types of techniques, which may be old's, that's why we disagree with the analyst.
5 0
3 years ago
Other questions:
  • The /tmp directory is a temporary directory and will not exist on a system at all times. True or False?
    15·1 answer
  • How can you prevent cyber bullying?
    13·2 answers
  • Person-name: String+setName(String name): void+getName(): String^Student-studentID: long+Student(String sname, long sid)+setID()
    10·1 answer
  • How much a T-mobile plan cost​
    11·2 answers
  • 1. Who was able to complete the puzzle the fastest in Trial 1?
    15·1 answer
  • Need answer ASAP
    8·2 answers
  • Ania has written this SimpleStopwatch class. In which line is she measuring the elapsed time?
    13·1 answer
  • Why does it keep saying this when I’m putting my right credit card number
    6·1 answer
  • Please help me !!
    10·1 answer
  • Without using parentheses, enter a formula in cell F4 that
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!