Ask Question
23 January, 13:52

Use the following variables:i, lo, hi, and result. Assume that lo and hi each are associated with an int and that result refers to 0. Write a while loop that adds the integers from lo up through hi (inclusive), and associates the sum with result. Your code should not change the values associated with lo and hi. Also, just use these variables: i, lo, hi, and result.

+3
Answers (1)
  1. 23 January, 16:47
    0
    public class num8 {

    public static void main (String[] args) {

    int lo = 0;

    int hi = 10;

    int result = 0;

    int i=0;

    while (i>=lo && i<=hi) {

    result = result+i;

    i++;

    }

    System. out. println (result);

    }

    }

    Explanation:

    In the above code written in Java, the variables lo and hi have been declared and assigned the values of 0 and 10 respectively

    The variable i is implemented as a counter for the control of the loop

    The code finds the sum of numbers between lo (0) and hi (10) which evaluates to 55

    In the while condition while (i>=lo && i<=hi) the counter i is incremented at every iteration by 1
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Use the following variables:i, lo, hi, and result. Assume that lo and hi each are associated with an int and that result refers to 0. Write ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers