// Write a program to sum first n even numbers using for loop


public class CWH_PS5 {
public static void main(String[] args) {
int sum =0;
int n = 5;
for(int i = 0 ; i < n; i++){
sum = sum + (
2*i);
}
System.
out.print("sum of first n numbers: ");
System.out.println(sum);
}
}

//output
sum of first n numbers: 20 Process finished with exit code 0

Post a Comment

0 Comments