I need help on this code I seem to have a problem regarding on summing the even numbers, what I want to happen is that the even numbers will be outputted and at the same time there will be an output where all the even numbers are summed within the inputted range of the user. I am just a beginner at coding and I hope some people can help me.
import java.util.*;
public class Loop
{
//Start
public static void main(String args[])
{
Scanner console = new Scanner(System.in) ;
System.out.println("Enter Start Number") ;
int start =console.nextInt();
System.out.println("Enter End Number") ;
int end =console.nextInt();
int sum = 0;
System.out.println("The even numbers between "+start+" and "+end+" are the following: ");
for (int r = start; r <= end; r++)
{
//if number%2 == 0 it means its an even number
if(r % 2 == 0)
{
System.out.println(r);
}
}
}
}