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
OlgaM077 [116]
3 years ago
11

Write a method called sum with a while loop that adds up all numbers between two numbers a and b. The values for a and b can be

passed to the sum method as parameters.
Computers and Technology
2 answers:
svetoff [14.1K]3 years ago
7 0
<h2>Answer:</h2>

  //Method sum header declaration.

   //The return type of the method be of type int,

   //since the sum of integer numbers is an integer.

   //It has the variables a and b as parameter

   public static int sum(int a, int b){

       

       //Since the method will sum numbers between a and b,

       //it implies that a and b are not inclusive.

       //Therefore, increment variable a by 1 before starting the loop

       //and make sure the loop does not get to b

       //by using the condition a < b rather than a <=b

       

       a++;

       

       //Declare and initialize to zero(0) a variable sum to hold the sum of the numbers

       int sum = 0;

       

       //Begin the while loop.

       //At each cycle of the loop, add the value of variable a to sum

       //and increment a by 1

       while(a < b) {        

           sum = sum + a;

           a++;

       }

       

       //at the end of the loop, return sum

       return sum;

       

   }        // End of method sum

   

<h2>Explanation:</h2>

The above code has been written in Java. It also contains comments explaining every section of the code. Please go through the comments for better understanding.

The overall code without comments is given as follows;

  public static int sum(int a, int b) {    

       a++;

       int sum = 0;

       

       while (a < b) {          

           sum = sum + a;

           a++;

      }  

       return sum;

       

   }

lana66690 [7]3 years ago
3 0

Answer:

   public static double sum(int a,int b){

       int sum =0;

       for(int i =a+1; i<b;i++){

         sum = sum+i;

       }

       return sum;

   }

Explanation:

A complete Java program that calls the method sum() is given below;

In creating the method sum; We used a for loop that starts at a+1 and ends at 1 less than b, this is because we want to grab the numbers between them and not including them.

In the body of the for loop, we add each element to the sum variable initially declared and initialized to zero.

public class TestClock {

   public static void main(String[] args) {

   int num1 = 5;

   int num2 = 10;

       System.out.println("The sum of numbers between "+num1+ " and "+num2+ " is "+sum(num1,num2));

   }

   public static double sum(int a,int b){

       int sum =0;

       for(int i =a+1; i<b;i++){

         sum = sum+i;

       }

       return sum;

   }

}

You might be interested in
How to fix this.. facing this problem to upload logo
AlekseyPX
I use an app called codechecker that helps with me having issues like that cause 99% of the time I'll mess it up.
7 0
3 years ago
you're adding new wires in your building for some new offices. the building has a false ceiling that holds the lights and provid
AlladinOne [14]

Based on the above, the  type of cable that need to be used by you is option B) Plenum rated cable.

<h3>What is plenum rated cable mean?</h3>

Plenum rated cable is known to be a kind of a cable that tends to have a unique form of insulation that is known to have low smoke and low flame attribute.

Note that the Plenum cable is one that need to be installed in any "air handling" space and as such, Based on the above, the  type of cable that need to be used by you is option B) Plenum rated cable.

Learn more about cable from

brainly.com/question/13258934

#SPJ1

See full question below

You are adding new wires in your building for some new offices. The building has a false ceiling that holds the lights and provides an air path for heating and air conditioning. You would like to run your Ethernet cables in this area. Which type of cable must you use?

A) STP cables

B) Plenum rated cable

C) Cat 5e or Cat 6a cables

D) PVC jacketed cables

E) Fiber optic cables

6 0
1 year ago
What is Network Address Translation (NAT) and how does it work in a network?
Allisa [31]

Answer:

 Network address translation (NAT) is a method for designing the IP address and it basically operate on router. NAT usually connect two network together and translate the unique and private address into the legal address.

Network address translation is a technique that works in network  for re-mapping the IP address into another by modify the network address information into the IP packet header. NAT gateway are used for the entire private network.  

The network address translation use both the security and economical purpose in an organization to limit the public IP address.

5 0
3 years ago
Give two reasons why mobile internet may not be available everywhere. ​
andreev551 [17]

Answer:

Mobile Internet is dependant on cellular signal. Many countries, e.g. in Africa, don't have any coverage at all. Furthermore, mobile data might also not be available in the mountains as there are no cell towers and the rough terrain usually either blocks the signal entirely or weakens it significantly.

4 0
3 years ago
NEEEEEEEEEEEEEEEEEEEEEEEEEEED HELP PLZ HURRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
AveGali [126]

Answer:

The first step after selecting the File tab is to select <u>New</u>

Explanation:

Invoice templates are used in order to streamline the billing in business.

In order to use such templates by fetching them online such as from Office.com following steps should be followed:

  • Start the Microsoft Word software.
  • Click on File tab.
  • From the drop down memory choose New.
  • In the Search menu type Invoices and it will display all available templates of Invoices.
  • On the homepage, their will be be an option for More Templates below the available ones. Click on it and choose the Category from left and click Invoices.
  • Select the template you want to use.

<h3>I hope it will help you!</h3>
7 0
4 years ago
Other questions:
  • Why is binary code made up of a series of ones and zeros?
    15·1 answer
  • Clep allows students to do all of thw following except which?
    9·2 answers
  • Write and test a function that takes the addresses of three double variables as arguments and that moves the value of the smalle
    11·1 answer
  • What is the financial aspect for a business as to what database software they will buy?
    6·1 answer
  • Discuss FOUR challenges that have an impact on domestic tourism
    6·1 answer
  • Examine the following piece of code and determine the data type of the function's return value.
    11·1 answer
  • Write a method intersect that accepts two sorted array lists of integers as parameters and returns a new list that contains only
    8·1 answer
  • Read a sentence from the console.
    6·1 answer
  • PLS ANSWER. MARKING CORRECT ANSWER AS BRAINLIEST
    11·1 answer
  • Application of optical fibre​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!