In my class we have been learning about loops. The problem is I have to fill-in the blanks to make this program display the sum of the integers 1 through 5.
public class Lab10A {
public static void main(
String[] args) {
int ________________;
for (________________________________) {
total += n;
}
System.out.println("The sum of the digits 1 to 5 is " + total);
}
}
Now this is what I was working on
public class Lab10A {
public static void main(String[] args) {
int n = 0;
for (n = 1; n <= 15; n ++) {
total += n;
}
System.out.println("The sum of the digits 1 to 5 is " + total);
}
}
This is just after many tries. So I asked the teacher and he told me I need a "broad scope" because you will add to its value inside the loop and display its value after the loop ends(which I have no idea what he means by that). I can't figure out what "broad scope" is.
The problem still wont compile and keeps telling me there is a problem with (total on
java line 5 and 7) and how it cannot resolve symbol.
Well I have been working on this program for like 3 hours and its been driving me nuts.
Thanks in advance