Hello everybody, sorry but I am a novice and I am not that great at programming. The program I need to create is that it adds all the even numbers from 2 inclusively until the inputed value. I am actually having problems at the for statement because I don't know how to add the integers there. Thanks for your consideration.
import java.util.Scanner;
public class Text2 { public static void main(String args[]) { int limit; int y; Scanner scan = new Scanner(System.in); System.out.println("Please input a value greater than 2"); limit = scan.nextInt();
while (limit <= 2) { System.out.println("Please reenter a value greater than 2"); limit = scan.nextInt(); } System.out.println(); System.out.println("Here is the sum"); for (int x = 2; x <= limit; x += 2) { System.ouut.println("I am confused what to do here"); } System.out.println("Done"); } }
System.out.println("Here is the sum");
y = 0; // initialize the sum variable
for (int x = 2; x <= limit; x += 2)
{
y = y + x; // add x to it each time through the loop
}
System.out.println(y); // print it out
System.out.println("Done");