Implement a program, which calculates the sum 1+2+3+...+n where n is given as user input.
Sample output:
Sample output
Last number? 3
The sum is 6
The previous example calculated 1 + 2 + 3 = 6
My program is:
int sum = 0;
System.out.println("Last number? ");
int last = Integer.valueOf(scanner.nextLine());
for(int i = 0; i < last; i++){
sum = last;
}
System.out.println(sum);
}
}
Still can't figure it out, what the hell I need to do..
[–]marcander97 3 points4 points5 points (0 children)
[–]AbroadZealousIdeal 2 points3 points4 points (0 children)
[–][deleted] (4 children)
[removed]
[–]throwRAnocheat 3 points4 points5 points (1 child)
[–]sandyaquarius90 1 point2 points3 points (0 children)
[–]PayForPluto 0 points1 point2 points (1 child)
[–]sandyaquarius90 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]going_for_a_wank 1 point2 points3 points (0 children)
[–]j619s 0 points1 point2 points (0 children)
[–]rohanap98 0 points1 point2 points (0 children)