Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// Implement the function so that all tests pass using a while loop. public stat

ID: 667668 • Letter: #

Question

// Implement the function so that all tests pass using a while loop.
   public static int addIntsInRangeUsingWhile(int start, int finish) {
   int sum = start;
   int count =1;
   while (count < finish){
       sum += count;
               count ++;
   }
   return sum;
   }

------------------------------------------------------------------------------------------

@Test
   public void testAddIntsInRangeUsingWhile() {
       assertEquals(10, HelloJava.addIntsInRangeUsingWhile(0,5));
   }

   @Test
   public void testAddIntsInRangeUsingWhile2() {
       int expected = 2 + 3 + 4;
       assertEquals(expected, HelloJava.addIntsInRangeUsingWhile(1,5));
   }


   @Test
   public void testAddIntsInRangeUsingWhile3() {
       int expected = 3 + 4 + 5;
       assertEquals(expected, HelloJava.addIntsInRangeUsingWhile(2,6));
   }

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class Ideone

{

     public static void main (String[] args) throws java.lang.Exception

     {

            public class HelloJava {

public static void main(String[] args) {

System.out.println("Hello World");

}

public static int addIntegers(int i, int j) {

return i + j;

}

public static int addIntsInRange(int start, int finish) {

int sum = 0;

for(int i = start + 1; i < finish; i++){

sum += i;

}

return sum;

}

// Implement the function so that all tests pass using a while loop.

public static int addIntsInRangeUsingWhile(int start, int finish) {

return 0;

}

// Implement the function so that all the tests pass. You can use any

// method you wish to determine the square root.

public static double findSquareRoot(double number) {

return 0.0;

}

}

}

}