Anonymous

Write A Java Program To Find Sum Of All Even Numbers For Given N Values?

2

2 Answers

Anonymous Profile
Anonymous answered
S=0+2+4+6+8...n

import java.io.*;
import java.util.*;
public class somme{
    public static void main(String [ ] args) {
     Scanner reed=new  Scanner (System.in);
    int n,s,I;
    System.out.println("entrer la valeur n");
    n=reed.nextInt();
    s=0;
    for (I=0;I<=n;I+=2){
    s=s+I;   
    }
    System.out.println("la somme est : "+s);
    }}

Answer Question

Anonymous