Java program that uses a loop to compute the sum of all even numbers between a and b (inclusive), where a and b are inputs
###### Posted by Samath
Last Updated: April 03, 2022

Write a Java program that uses a loop to compute the sum of all even numbers between  a and  b (inclusive), where  a and  b are inputs.

Code:

```import java.util.Scanner;

public class Main
{
public static void main(String[] args) {

Scanner input = new Scanner(System.in);
System.out.print("a: ");
int a_input = input.nextInt();
System.out.print("b: ");
int b_input = input.nextInt();

double result = 0;
for (int i = a_input; i <= b_input; i++) {
if (i % 2 == 0) {
result += i;
}
}
System.out.println("Result: " + result);
}
}
```
###### Java program that uses a loop to compute the sum of all even numbers between 2 and 100 (inclusive)
Samath | Apr 03, 2022
###### Java program that uses a loop to compute the sum of all squares between 1 and 100 (inclusive)
Samath | Apr 03, 2022
###### Java program that uses a loop to compute the sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)
Samath | Apr 03, 2022
###### C Program to Compute sum of the array elements using pointers
Samath | Jan 02, 2017
###### Java program that read a sequence of integer inputs and print the smallest and largest of the inputs
Samath | Apr 03, 2022
###### Java program that read a sequence of integer inputs and print the number of even and odd inputs.
Samath | Apr 03, 2022
###### Sum of two values in C
Samath | Nov 09, 2014
###### C Program to find sum of two numbers
Samath | Jan 02, 2017
###### C++ Calculate the sum from 1 to 100
Samath | Jan 05, 2017
###### Find factorial using loop in C++
Samath | Nov 02, 2014
###### C Program that Print First 10 Natural Numbers using For, While and Do-While Loop
Samath | Jan 02, 2017
###### Java program that reads in three floatingĀ­ point numbers and prints the largest of the three inputs
Samath | Feb 12, 2021
###### Javascript program that check if a word is palindrome using one for loop
SceDev | Feb 17, 2024
###### Write a C++ program that find the sum of all even numbers between 1 and 30 excluding 6, 8, 24 and 28
Samath | Nov 02, 2014