I really don't understand how to find the sum of a sequence in Java. For instance, the program will ask for the input of the first and last number of the sequence and add the sum of the sequence(3 + 4 + 5 = 12). My System.out.println() isn't working as well. Why is this?
import java.util.Scanner;
public class SumOfASequenceTheSequel {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("First number?");
int first = Integer.valueOf(scanner.nextLine());
System.out.println("Second number?");
int second = Integer.valueOf(scanner.nextLine());
int sum = 0;
int i = first;
while (i <= second) {
sum = sum + i;
i = i++;
}
System.out.println("The sum is " + sum);
}
}