Menu
Question Index
...


Write a program to find the sum of all even numbers till a given number.

Input Output
7 2 + 4 + 6 = 12
15 2 + 4 + 6 + 8 + 10 + 12 + 14 = 56

class SumOfEvenNumbers

{    public static void main(String s[])
    {
        System.out.println("Sum of even numbers till 5 is " + sum_of_even_numbers(5));

    }


public static int sum_of_even_numbers(int input)
{
int output = 0;
//Write code here to find the sum of even numbers till input and assign it to output
return output;
}
}

Doubts

Problems

Topic: for Loop In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App