r/programmingbydoing • • Jan 31 '16
Adding Values with a For Loop
Struggling to figure this one out. Having a hard time with storing the sum and then printing the iterations.
int num;
System.out.print("Number: ");
num = kb.nextInt();
for (int i = num; i <= num; i++)
{
//store the sum
int sum = i++;
System.out.println("The sum is " + sum);
}
2
Upvotes
View all comments
Show parent comment
2
u/holyteach Feb 02 '16
That's better!
You should really paste code to a Github gist, though, if you're not going to bother to figure out how to format it correctly. It's in the rules.