Ask Question
12 February, 14:37

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.

+2
Answers (1)
  1. 12 February, 15:41
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers