228k views
4 votes
Assume the int variables i ,lo , hi , and result have been declared and that lo and hi have been initialized.

Assume further that result has been initialized to the value 0.
Write a for loop that adds the integers from lo up through hi (inclusive), and stores the result in result.
Do not declare any additional variables --
use only i,lo,hi.
------------------------
import java.util.Scanner;
public class forloop_add{
public static void main(String args[]) {
int i,lo=1,hi=3,result=0;
Scanner scanner =new Scanner(System.in);
System.out.println("Enter the lower limit:");
lo=scanner.nextInt();
System.out.println("Enter the upper limit:");
hi=scanner.nextInt();
///{
//write your code here
//start
//end
///}
System.out.println("Result:"+result);
}
}

1 Answer

3 votes

Answer:

I don't get this question, what is the point of initializing lo and hi if you're gonna read an input of both later, which is gonna override?

Step-by-step explanation:

User IMatoria
by
4.4k points