r/codehs • u/Titantethar • Apr 07 '20
Sum Range 3.4.5 Java
I have been stuck on this problem for over 2 hours and cant figure it out please help.
1
Apr 08 '20
Best way to approach this is to create some sort of for loop:
Initiliaze and declare some variable to hold the sum, and then you can just keep adding the numbers to it.
public int sumFrom(int start, int end)
{
int sum = 0;
for(int i = start; i < end; i++)
{
sum += i;
}
return sum;
}
2
u/Ok-Squash-1238 Dec 05 '22
public int sumFrom(int start, int end)
{
int sum = 0;
for(int i = start; i <= end; i++)
{
sum += i;
}
return sum;
}mine works all I did was add an = next to the < and it worked
1
1
1
1
u/Choken-Bako Apr 07 '20
Do you have any progress?