Answer to Question #3533 in Java | JSP | JSF for Y mukundareddy

Question #3533
Write a program to print the sum of the n even numbers
1
Expert's answer
2012-03-16T09:17:12-0400
import java.util.Scanner;




public class Main {




public static void main(String[] args) {

int n, sum=0;

Scanner in = new Scanner(System.in);

System.out.print("Enter n: ");

n = in.nextInt();

for(int i = 0; i <= n; i++)

sum += i;

System.out.println("sum = " + sum);

}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS