Problem: Write a program to sum the following series:
1 + (1 + 2) + (1+ 2 + 3) + (1 + 2 + 3 + .........+ n)
Hey guys just stuck on a problem here. So far I have:
public static void main(String[] args) {
int sum = 1;
System.out.println("input number of times for series to run:");
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
for (int i = 0; i <= n;i++){
sum = sum + (i+n);
System.out.println(sum);
}
}
}
But the output answers is always wrong. Ive tried using the += operator and no joy. And also had before this sum = i + (i + n);
could ye tell me what I'm doing wrong?