Java: Increment by 2 the two inputted integer

Some Notes:

1- in.nextInt(); reads an integer from the user, blocks until the user enters an integer into the console and presses ENTER. The result integer has to be saved in order to use it later on, and to do so save it into a variable, something like this:

int value = in.nextInt();

In your code, you need to assign the 3 integers that the user enters to the corresponding variables:

System.out.println("Enter min value: ");
min = in.nextInt();
System.out.println("Enter max value: ");
max = in.nextInt();
System.out.println("Enter increment value: ");
increment = in.nextInt();

2- You are implementing the loop very well, but you just need to use the user’s inputs rather than using explicit integers:

for(int i = min; i <= max; i += increment)

Leave a Comment