import java.util.*; public class SumOfAllEvens { public static void main (String[] args) { Scanner s = new Scanner (System.in); //for (int i=1; i<4; i++){ int usernumber; int sum=0; System.out.print ("Please enter an integer: "); // Prompt usernumber = s.nextInt(); for (int j=2; j<=usernumber; j=j+2){ if (usernumber<2) System.out.println ("Error"); else System.out.println ("The sum of all evens from 2 to " + usernumber + " (inclusive) is " + (j+usernumber) + " ."); //sum=sum+j; //} } } }
I'm supposed to use a for loop that runs until it reaches the number input by the user, but I'm not sure how to tell the program to add the user's number along with all of the even numbers in between the user input and 2.