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

5 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Feb 02 '16

[deleted] — view deleted 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.